[Tex/LaTex] How to properly change page offsets

marginsplain-tex

Suppose that we need to change margins. This cannot be done only by changing \hsize and \vsize, because of the default offset of 1in.
There is a possibility to change \hoffset and \voffset directly, but this becomes cumbersome. Is there a more universal solution, using output routine, or some other trick? Also, how to change left offset if the page has even number (for two-pages design)?

Best Answer

Is there a more universal solution, using output routine, or some other trick?

For plain TeX, the only "more universal" that I know is the OPmac macros, for example:

\input opmac
\margins/2 a5 (1,1,1,1.4)cm % A5 paper + 1cm margins in two-pages design

In this case, the declared margins are those of the odd pages. The margins of the even pages are just mirrored accordingly. Run texdoc opmac and see section 16, or go the OPmac site for more information.

For LaTeX, you can touch the low level lengths that you can see with the package layout as \hoffset, or as more "universal" (kindly, simple, easy) way, deal with some of the packages of the topic geometry in CTAN, as typearea,anysize, or why not, the ubicuous geometry.

To know that approaches each package, run texdoc <package>. In the case of geometry it is a proper approach as usually it work and there are a nice documentation. With other packages may be you will be less lucky, but you always can run texdoc <package>.sty (now with the extension) and see the source code to understand which methods have been used.

how to change left offset if the page has even number (for two-pages design)?

In LaTeX, use the \layout command (of the package layout) in the document environment!

You will see that in a twoside article \hoffset is always 0pt and it is the same command in odd/even pages. But you but can change \oddsidemargin and \evensidemargin.

In plain TeX you can create these lengths and set \hoffset to odd/even pages conditionally:

% Stolen from a Dan Luecking's answer at comp.text.tex 
\newdimen\oddsidemargin
\newdimen\evensidemargin
\oddsidemargin=.25truein  
\evensidemargin=1truein  
\output={\hoffset=\ifodd\pageno\oddsidemargin\else%
\evensidemargin\fi\plainoutput}

\oddsidemargin=300pt % only to test ...
\evensidemargin=10pt

odd page 
\vfil \break
even page 
\bye