One of the nicest features of LaTeX is having good layout by default. For many English uses the standard document classes are appropriate, for some non-English languages there are good adaptations for local typographic conventions (like mwcls for Polish texts). As necessary for internationalized use, they support many paper sizes. Unfortunately, if a PDF is generated from such document, it is treated by viewers as a Letter or A4 page even if it is completely different.
The UK TeX FAQ explains this problem and suggests several solutions – all of which are packages or document classes using their own page layouts. Since the document classes which I use already have appropriate layout, I decided to solve this problem differently.
As stated in the FAQ and the pdfTeX manual (page 20, the texdoc pdftex command in TeXLive shows this documentation), the \pdfpagewidth and \pdfpageheight dimensions are used to set the PDF page size. LaTeX stores the same data in \paperwidth and \paperheight (classes.pdf page 3 as available in TeXLive). Manuals of XeTeX and LuaTeX show that these TeX implementations also support these commands, so using any of them the following code will set the appropriate page size:
\pdfpagewidth=\paperwidth \pdfpageheight=\paperheight
This code won’t work with TeX implementations without these commands. When these commands are undefined it will produce some error messages and output some text. The simplest solution is to not use these commands when they are not available, for example with the following code:
\makeatletter
\@ifundefined{pdfpagewidth}{}{%
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
}
\makeatother
The UK TeX FAQ suggests using the ifpdf package for detecting PDF support which here would be too specific – support for XeTeX would require using another package, also it is not a problem to use the above code when making a DVI file. It would not make DVIs with correct page size, but setting this would depend on the DVI driver and PDF-producing TeX variants have other useful advantages.

Leave a comment