[Tex/LaTex] Why does the hyperref package change the paper size

hyperrefpaper-size

The other day I was shocked to discover that some of my LaTeX-produced documents had US letter paper size. I do not live in the US.

It took me some time to find out that this was caused by the hyperref package. Why does this package change the paper size? Can I prevent it from doing this, so the system default paper size will be used?


Minimal example:

\documentclass[]{article}

% uncomment this to trigger switch to US letter size
%\usepackage{hyperref}

\begin{document}
x
\end{document}

I compile with pdflatex.


I am using MacTeX 2016. The default size on my system is A4. tlmgr paper outputs:

Current context paper size (from /usr/local/texlive/2016/texmf-config/tex/context/user/cont-sys.tex): a4
Current dvipdfmx paper size (from /usr/local/texlive/2016/texmf-config/dvipdfmx/dvipdfmx.cfg): a4
Current dvips paper size (from /usr/local/texlive/2016/texmf-config/dvips/config/config.ps): a4
Current pdftex paper size (from /usr/local/texlive/2016/texmf-config/tex/generic/config/pdftexconfig.tex): a4
Current psutils paper size (from /usr/local/texlive/2016/texmf-config/psutils/paper.cfg): a4
Current xdvi paper size (from /usr/local/texlive/2016/texmf-config/xdvi/XDvi): a4

I know that I can just use \documentclass[a4paper]{article} to get A4, but I was under the impression that the system will just use the default when a size is not specified

Best Answer

Just because the output format has a default paper size doesn't mean that LaTeX knows about it.

In the "old days", there was no communication between TeX and whatever printed/displayed the DVI file w.r.t. the size of the paper. Hence the reason for the defaults you mention — if you're American, you'll set up your page margins and so on for letter paper, so when you go to print/display the page it makes sense to show a letter-sized page.

Remember that LaTeX is intended to produce the same documents given the same input on different computers (packages changing their behaviour notwithstanding). So you must always declare the class option [a4paper] if you want your documents printed or displayed on A4-sized paper.

To answer your specific question, since pdfTeX there have been TeX commands to explicitly set and communicate the page size to the output driver; since LaTeX itself has been largely frozen it doesn't used these and the vanilla behaviour is to rely on the defaults you talk about to set the page sizes.

But hyperref is a modern package and refers to many PDF internals, and one of the things it also does is ensure that the paper size of the PDF matches the paper size that LaTeX used.