[Tex/LaTex] Left margin wider than right one

marginsplain-textex-core

Why is the left margin wider than the right one? Each of them should be 1 inch wide:

If you run TEX without modifying the plain TEX format, you get pages that are numbered at the bottom; and each page will be approximately 8.5 inches wide and 11 inches tall, including 1-inch margins at all four sides. [The TeXbook, p.251]

\moveleft2cm\vbox{\hrule width2cm}
\moveright\hsize\vbox{\hrule width2cm}

enter image description here

UPDATE

How can the document know the size of paper it is being typeset on?

Best Answer

This should explain the apparent contradiction; compile with pdftex

\pdfpageheight=11in
\pdfpagewidth=8.5in
\moveleft2cm\vbox{\hrule width2cm}
\moveright\hsize\vbox{\hrule width2cm}
\bye

If you use tex+dvips+ps2pdf for producing a PDF file, change the first two lines into

\special{papersize=8.5in,11in}

You'll get

enter image description here

The fact is that the standard setup of TeX distributions, regarding PDF output, is ISO A4 paper and not Letter paper.

A rudimentary test for the various situations might be as follows:

\def\dvipsletterpaper{\special{papersize=8.5in,11in}}
\def\pdfletterpaper{\pdfpagewidth=8.5in \pdfpageheight=11in }
\ifx\pdfoutput\undefined
  % we're either with Knuth TeX or XeTeX
  \ifx\XeTeXversion\undefined
    % we're with Knuth TeX
    \dvipsletterpaper
  \else
    % we're with XeTeX
    \pdfletterpaper
  \fi
\else
  % we're either in pdfTeX or LuaTeX, we assume \pdfoutput is an integer
  \ifnum\pdfoutput>0
    % PDF output
    \pdfletterpaper
  \else
    % DVI output
    \dvipsletterpaper
  \fi
\fi