# 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. Jan 20, 2011 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. Jan 20, 2011 at 21:54
• No, xetex and pgfpages...but I think you knew that.:-P Jan 21, 2011 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). Sep 14, 2010 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? Jan 7, 2014 at 6:26
• @Ricardo Same problem here. Did you find a solution? Jan 19, 2014 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] Jan 20, 2014 at 5:14
• If you add that in the preamble of your xelatex beamer document it should work... for me it works! Jan 20, 2014 at 5:16

The answer to your question “is this ever going to get fixed?” is yes. Because your MWE works fine for me as of now. I don't know when the bug got fixed.

Moreover, the \renewcommand\pgfsetupphysicalpagesizes workaround now produces unexpected behavior. The physical page is clipped to a normal slide's dimension, which means most of the handout content is invisible. If I apply it to your MWE, I get a page shaped like a regular slide (not A4), with one frame that has its right and bottom edges cut off.

I discovered this because a personal class file I wrote back in 2011 stopped working, and it was these two lines that were the culprit.