7

Situation, probably known

I know the pdf-page-size can be changed in LaTeX using package geometry. But how to do it in plain-TeX?

E.g. changing page related parameters, like \vsize or \hoffset, do introduce changes, but don't seem to touch the paper format written into the pdf, here 8,27 x 11.69 in.

% setting (some) page parameters
\vsize 3in
\pagegoal \vsize
\hsize 4in
\hoffset 2in
\topskip 1.5in


\headline{My head \hrulefill}\footline{\hrulefill Your foot - \the\pageno}

Lorem ipsum dolor sit amet consectetuer nibh enim congue porta vel. Commodo hendrerit pellentesque Curabitur quis consectetuer Integer laoreet ante adipiscing aliquet. Congue condimentum tempus lorem nec leo et semper Aliquam senectus augue. Dolor massa vitae Nullam Sed est dignissim penatibus tellus orci Aliquam. Nulla sed iaculis aliquet massa ipsum Nullam id ipsum vitae sapien. Consequat Vestibulum Ut id morbi Aliquam lobortis Fusce Lorem at platea. Nibh.

Justo elit montes nulla justo at quis nascetur diam Morbi Phasellus. Vestibulum enim Vestibulum semper Curabitur consequat ante penatibus quis ut auctor. Vestibulum nunc Aliquam interdum non wisi congue nec interdum Sed orci. Sed Nam consequat enim non sem dignissim vitae eleifend mauris mauris. Curabitur enim ligula massa orci aliquam ac Phasellus semper id tortor. Magna.

Vitae laoreet lorem Nulla Nunc Nunc nunc convallis nibh venenatis Vivamus. Curabitur laoreet felis congue interdum condimentum augue at condimentum id Aliquam. Suspendisse adipiscing velit ipsum ipsum Ut Aenean pellentesque consequat enim et. 

\bye

page size

result

Question

How to solve this? Couldn't find an answer here, in books or on the web for days. I'm using current TexWorks from MikTeX, compiling with pdftex.

3 Answers 3

11

TeX (as intended by Knuth) has no notion whatsoever of page size. Printing or viewing has always been DVI drivers' job.

Only exception is that, by Knuth's decree, all drivers must account for an origin that's one inch from the left edge and one inch from the top edge of the paper, whatever paper (maybe only virtual paper on screen) is ultimately used.

Since pdftex is its own driver, passing to it the desired paper size is necessary and it provides a few primitives for the job:

  • \pdfpagewidth and \pdfpageheight are the main ones;
  • \pdfhorigin and \pdfvorigin are next.

Suppose you want that the page width is 10in and the page height 9in, with the text block having its top left corner 3in from both the left and top edges.

\pdfpagewidth=10truein
\pdfpageheight=9truein
\pdfhorigin=3truein
\pdfvorigin=3truein

\hsize=4truein
\vsize=3truein

\input plipsum

\lipsum{3-7}

\bye

enter image description here

Sorry for the lengths in centimeters, but, you know, almost everybody uses them. 😊 Anyway, 25.5cm are exactly 10in and 22.86cm are 9in (the viewer I use rounds to one decimal digit).

Don't abuse \hoffset or \voffset for this. Also, setting \topskip is not the right tool for placing the headline: this has to be done at the output routine level.

Setting \pagegoal does nothing at all, because this parameter is reset whenever a page is shipped out (including the start of the job).

0
7

I recommend that \pdfhorigin and \pdfvorigin are set to 0pt in order to set the reference point to left-upper corner of the paper. Then you can set \hoffset and \voffset as margins measured from the paper border, you don't need to include +-1in calculation in your macros and the life is simpler. The \pdfpagewidth and \pdfpageheight should be set to the real paper width and height.

For example, if you want to have all margins 2cm with A4 paper size, then you can set:

\pdfhorigin=0pt  \pdfvorigin=0pt % We don't support a sub-optimal Knuth's decision about (1in, 1in)

\pdfpagewidth=210mm  \pdfpageheight=297mm  % A4 paper dimensions

\hoffset=2cm
\voffset=2cm
\hsize=\dimexpr \pdfpagewidth - 2\hoffset \relax
\vsize= \dimexpr \pdfpageheight - 2\voffset \relax

Note, that OpTeX sets \pdfhorigin and \pdfvorigin to 0pt because (1in,1in) reference point position is just annoying.

1
  • In LuaTeX, instead of changing \pdfhorigin, you can use \pagetopoffset and \pageleftoffset instead of \hoffset and \voffset, they don't have the annoying 1in, and this way \pagerightoffset won't have the annoying 1in to remember (for RTL typesetting).
    – Udi Fogiel
    Apr 26 at 8:43
4

Solution

The solution is already (almost) there: compiling with pdftex. According to its User Manual all that's needed to be done is adding required pdf-primitives:

% setting pdf-page parameters  <<<<<< new
\pdfoutput 1
\pdfpageheight 5in
\pdfpagewidth 8in

% setting (some) page parameters
\vsize 3in
\pagegoal \vsize
\hsize 4in
\hoffset 2in
\topskip 1.5in


\headline{My head \hrulefill}\footline{\hrulefill Your foot - \the\pageno}

Lorem ipsum dolor sit amet consectetuer nibh enim congue porta vel. Commodo hendrerit pellentesque Curabitur quis consectetuer Integer laoreet ante adipiscing aliquet. Congue condimentum tempus lorem nec leo et semper Aliquam senectus augue. Dolor massa vitae Nullam Sed est dignissim penatibus tellus orci Aliquam. Nulla sed iaculis aliquet massa ipsum Nullam id ipsum vitae sapien. Consequat Vestibulum Ut id morbi Aliquam lobortis Fusce Lorem at platea. Nibh.

Justo elit montes nulla justo at quis nascetur diam Morbi Phasellus. Vestibulum enim Vestibulum semper Curabitur consequat ante penatibus quis ut auctor. Vestibulum nunc Aliquam interdum non wisi congue nec interdum Sed orci. Sed Nam consequat enim non sem dignissim vitae eleifend mauris mauris. Curabitur enim ligula massa orci aliquam ac Phasellus semper id tortor. Magna.

Vitae laoreet lorem Nulla Nunc Nunc nunc convallis nibh venenatis Vivamus. Curabitur laoreet felis congue interdum condimentum augue at condimentum id Aliquam. Suspendisse adipiscing velit ipsum ipsum Ut Aenean pellentesque consequat enim et. 

\bye

Now the page size is at 8 x 5 in, as indicated.

size

result

Backgound

This problem is indeed well known and not-new. See e.g. this question about page margins from 2013 for several TeX compilers, especially the comments.

This puzzle may exist probably because nowadays we are used to associate "printed area" with "paper size". This is a valid assumption with a text processor using an office or home printer, which most of the time use letter or A4 paper.

However, TeX was designed with typesetting in mind, or better the way Gutenberg, China long before him, et. al., created printed paper.

Which means, you have a printing block (like typeset q or n, which will move under the block labeled h in "Fig.1 Printing press"), which roughly contains the area (and a bit more) between the header and footer shown above. Coordinates on the set typeset, so to say, are indicated there by the TeX parameters like \vsize or \hoffset, and its placement algorithms.

Paper size, on the contrary, may or may not be known before actually printing, and it certainly will have to be larger, and will be cut into smaller pieces later. Think of the pdf-primitives from pdftex taking care of this (electronic) paper.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .