# Why does the hyperref package change the paper 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

• It's wrong not to pass a4paper to \documentclass in the first place, because you get a type block not in the format for ISO A4 (and not centered in the page). – egreg Mar 2 '17 at 14:02
• @egreg Could you elaborate on that? I do not know what is a type block. From my perspective, all I could see was that: 1. paper size is implemented as an explicitly optional setting 2. there is such a thing as a default paper size for the system. Because of this, I found your comment that not specifying the paper size is wrong very surprising. I am sure many other people would too. Thus an answer explaining it would be useful for everyone. – Szabolcs Mar 2 '17 at 14:18
• @egreg Based on your comment, I found the answer. The default size applies to plain TeX. LaTeX uses US letter if no other size is given. If the default size is A4, LaTeX will put a block of text meant fit on US letter onto an A4 size page. – Szabolcs Mar 2 '17 at 14:31
• I still do not understand the second warning give in my link, though. It says, "The a4paper option with the article document class by itself has no effect. It will only affect the page size in connection with some appropriate package, like the geometry package or the hyperref package." – Szabolcs Mar 2 '17 at 14:32
• @Szabolcs — that isn't quite right; the class option will still adjust the typesetting of the document but it won't automatically force the paper size to be "correct". See my answer below for more detail on that. – Will Robertson Mar 2 '17 at 14:36

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.

You can test the layout e.g. with the layout package.

\documentclass[a4paper]{article}
\usepackage{layout}
\begin{document}
\layout
\end{document}


This gives this values for letter (without a4paper):

and this with a4paper:

As you can see quite some values differ, most importantly paperwidth and paperheight.

Without hyperref, the pdf page width will be set with the default of your system. In your case this means the pdf paperwidth and the tex paperwidth are actually different.

hyperref (or graphicx) will force the pdf paperwidth in sync with your tex paperwidth.

It's wrong not to pass the a4paper in the first place.

Compare the two printouts of a simple \kant document. Can you see the difference? In the “no a4paper” case, the type block is placed in a wrong position and has the wrong dimensions. Specifically, the left margin is larger than the right margin, and the bottom margin is larger than what it should be.

\documentclass[
a4paper
]{article}
\usepackage{kantlipsum}
\begin{document}
\kant[1-10]
\end{document}


## With a4paper

• Some years have passed. Maybe things have changed. Is there a way now to protect oneself from such problems? (1) Is there a way to set A4 system-wide and trust that the setting will be picked up? (2) Alternatively, is there a way to get a big fat warning (or better: error message) if I did not explicitly specify the paper size? You say it's wrong not to specify it, and you demonstrate that things go wrong. It would make sense to get an error. – Szabolcs Jul 14 '20 at 13:22
• I guess the best thing I can do is to have a starting template that I use for all new documents, and specify a4paper in it. Let me know if you have a better idea. – Szabolcs Jul 14 '20 at 13:24