# xelatex and pgfpages compatibility

I've just switched from pdflatex to xelatex for my lectures to take advantage of the unicode-math package so that I can change the colours of all my mathematics. When compiling the "handout" version last night, I found that it didn't work as I expected. I use the pgfpages package to produce the handout as a 4-up document (with a nice box round each frame) to save paper. But the page size in the resulting document was that of one slide, not a full a4 piece of paper. A little googling led me to a quick fix on tug:

\newlength\hackpaperwidth \hackpaperwidth210mm
\newlength\hackpaperheight \hackpaperheight297mm
\RequirePackage{everyshi}
\EveryShipout{%
\special{papersize=\the\hackpaperwidth,\the\hackpaperheight}}

with the comment (from the author):

Probably not the cleanest way of doing things, so if someone has a better idea and/or can locate the bug exactly, comments welcome.

There were no follow-up comments, but it was dated November 2008. In June 2009, there's a similar-looking problem on the xetex mailing list with this response:

That's a reported (and probably not fixed yet) problem in pgfpages. Use this to tell pgfpages how to set page sizes in XeLaTeX:

\renewcommand\pgfsetupphysicalpagesizes{%
\pdfpagewidth\pgfphysicalwidth\pdfpageheight\pgfphysicalheight%
}

(These are (linked from) the top two hits on google for xelatex pgfpages).

My real question is: is this going to get fixed? But that's not a good tex.SE question. So my attempt to make it into a good question is:

The second of the above seems the better of the two. Is that the best way to fix this problem?

PS The MWE from the first linked post is still a suitable one:

\documentclass{beamer}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper]
\begin{document}
\frame{\frametitle{A} foo}
\frame{\frametitle{B} bar}
\end{document}
-
Thanks for writing this up so well. I'm having the same issue and it looks like I have to use the same workaround. –  Matthew Leingang Jan 20 '11 at 19:04
@Matthew: You mean that you are using coloured letters in maths as well? Only kidding. I'm still using the workaround too. –  Loop Space Jan 20 '11 at 21:54
No, xetex and pgfpages...but I think you knew that.:-P –  Matthew Leingang Jan 21 '11 at 17:02

Use option dvipdfm:

\documentclass[dvipdfm]{beamer}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper]
\begin{document}
\frame{\frametitle{A} foo}
\frame{\frametitle{B} bar}
\end{document}
-
In my first test, that just fixed it for the first page but all the other pages were as before (but that was a test on a complicated document so I'll try it on the MWE too). –  Loop Space Sep 14 '10 at 8:01
Using this option with XeLaTex throws the following error for the package hyperref: "Wrong DVI mode driver option dvipdfm', because XeTeX is running.Wrong DVI mode driver option dvipdfm' because XeTeX is running." Does anybody know if this is another incompatibility? –  Ricardo Jan 7 '14 at 6:26
@Ricardo Same problem here. Did you find a solution? –  JerryWho Jan 19 '14 at 18:06
Yes, @JerryWho. It is a matter of redefining the value for the physical page: \usepackage{pgfpages} \renewcommand\pgfsetupphysicalpagesizes {\pdfpagewidth\pgfphysicalwidth\pdfpageheight\pgfphysicalheight} \pgfpagesuselayout{2 on 1}[letterpaper,border shrink=5mm,landscape] –  Ricardo Jan 20 '14 at 5:14
If you add that in the preamble of your xelatex beamer document it should work... for me it works! –  Ricardo Jan 20 '14 at 5:16