% \iffalse
% This is the twoup package, twoup.dtx
% Copyright 2001 by Mogens Lemvig Hansen.
%
% Run this file through LaTeX and read the documentation in twoup.dvi
%
% This program may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% This program consists of the files twoup.dtx and twoup.ins
%
%<*docdriver>
\documentclass{ltxdoc}[1996/01/11]
\usepackage{url}
%\discretionaries |~!@$%^&*()_+`=#{"}[]:;'<>,.?\/|
\CodelineIndex%\EnableCrossrefs
\makeatletter
\newcommand{\nextlinelabel}[2][1]{\@bsphack
   \@tempcnta\c@CodelineNo
   \advance\@tempcnta#1\relax
   \def\@currentlabel{\the\@tempcnta}\label{#2}%
   \@esphack}
\makeatother
\begin{document} \DocInput{twoup.dtx} \end{document}
%</docdriver>
% \fi
% \CheckSum{253}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \def\fileversion{1.1} \def\filedate{2001/04/03} \def\docdate{\filedate}
% \title{The \textsf{twoup} Package\thanks{This file describes version
%   \fileversion, \filedate.}}
% \author{\copyright\ Mogens Lemvig Hansen\thanks{%
%    The \textsf{twoup} package is distributed under the \LaTeX\ Project
%    Public License; please see Section~\ref{sec:license}.}\\
% mlhansen@uniserve.com}
% \date{\docdate}
% \maketitle
% \begin{abstract}
%    The \textsf{twoup} package provides the necessary \LaTeX\ setup for
%    two-up or booklet printing with the psnup program and friends.
% \end{abstract}
%
% \tableofcontents\bigskip
%
% MiK\TeX\ and many other \TeX\ implementations include tools for massaging
% postscript into two-up printing\footnote{That is, printing two logical pages
% side by side on one side of one sheet of paper.} and booklets.
% The \textsf{twoup} package provides a page layout designed for two-up
% printing and gives advise on how
% to use the postscript tools.
%
% \section{Usage}
% Give the paper size you intend to print on as an option to
% \verb:\documentclass:\footnote{If you intend to print on your default paper
% size, you do not have to give any paper size option.} and load the
% \textsf{twoup} package.
% For example:
% \begin{quote}
% \verb:\documentclass[letterpaper,12pt]{article}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
% The \textsf{twoup} package re-calculates the paper size and margins for
% two-up printing.\footnote{If you print on \texttt{a4paper}, \textsf{twoup}
% calculates the same paper size as the \texttt{a5paper} option but with
% different (smaller) margins.  You may consider this discrepancy either a bug
% or a feature.}  When you run your .tex file through \LaTeX, the
% \textsf{twoup} package will tell you which options to use with the psnup program; 
% look for the psnup
% command line near the end of the transcript.\footnote{Both on screen and 
% in the .log file.}  If you give a paper size
% option, the \textsf{twoup} package will also tell you which lines you will
% have to add to your postscript file by hand.
%
% Run the .dvi file through dvips\footnote{The current version of
% the \textsf{twoup} package requires that you use dvips.  If you want to use
% some other .dvi-to-postscript program, please see code line~\ref{line:dvips}
% and the commentary around it.} to make a postscript file.
% \begin{quote}
% \verb:dvips: \meta{file}
% \end{quote}
%
% Then run psnup with the options that the \textsf{twoup} package gave you
% above.  Even Win95 allows you to cut-and-paste the command line
% which could look something like this:
% \begin{quote}
% \verb:psnup: \verb:-pletter: \verb:-W396.0pt:
% \verb:-H612.0pt: \verb:-2: \meta{file}\verb:.ps: \meta{twoup}\verb:.ps:
% \end{quote}
%
% The postscript file, \meta{twoup}\verb:.ps:, has by now lost all
% consciousness of which paper size it is to be printed on.  If you are about
% to print on your printer's default paper size, that is no problem.  To print on
% any other paper size you most likely have to place a paper size command in
% \meta{twoup}\verb:.ps:.  With a plain text
% editor add the lines \textsf{twoup} gave you in the \LaTeX\ run to
% \meta{twoup}\verb:.ps:. 
% The lines to add could look like this:
% \begin{quote}
% \verb;%%BeginPaperSize: letter;\\
% \verb;letter;\\
% \verb;%%EndPaperSize;
% \end{quote}
% Place the new lines just after the
% \verb:%%EndComments: line near the top of \meta{twoup}\verb:.ps:.
%
% \subsection{Booklets}
% The \LaTeX\ side of making booklets is much like simple two-up.  However,
% you may want to use the \texttt{twoside} option to \verb:\documentclass: to
% make the inner margins a bit larger etc.
% For example:
% \begin{quote}
% \verb:\documentclass[legalpaper,11pt,twoside]{article}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
% As above, the \textsf{twoup} package will advise you on which options to use
% with the psnup program.  Run your .dvi file through dvips:
% \begin{quote}
% \verb:dvips: \meta{file}
% \end{quote}
%
% Now the fun begins:  Before using psnup you must use the psbook program to
% fold your postscript file into a signature:
% \begin{quote}
% \verb:psbook: \meta{file}\verb:.ps: \meta{book}\verb:.ps:
% \end{quote}
% The number of pages in a signature must be divisible by four, so psbook may
% add a few blank pages to the end of your booklet.
% Run the result through psnup with the options
% the \textsf{twoup} package calculated in the \LaTeX\ run.
% The command line could look something like this:
% \begin{quote}
% \verb:psnup: \verb:-plegal: \verb:-W504.0pt:
% \verb:-H612.0pt: \verb:-2: \meta{book}\verb:.ps: \meta{twoup}\verb:.ps:
% \end{quote}
%
% Unless you are about to print on your printer's default paper size, add the
% paper size command to \meta{twoup}\verb:.ps: as above.
%
% You can print your postscript file, \meta{twoup}\verb:.ps:, now, but if you
% want to print double sided, you may have to split the file in two with the
% psselect program:
% \begin{quote}
% \verb:psselect: \verb:-o: \meta{twoup}\verb:.ps: \meta{odd}\verb:.ps:\\
% \verb:psselect: \verb:-e: \meta{twoup}\verb:.ps: \meta{even}\verb:.ps:
% \end{quote}
% Then print \meta{odd}\verb:.ps:, turn the paper over, and print
% \meta{even}\verb:.ps:.\footnote{Depending on your printer, you may want to
% use psselect's \texttt{-r} option to print the \meta{even} pages in reverse
% order.}
%
% \subsection{Options}
% By default the \textsf{twoup} package leaves room for running headers and
% footers.  Use the \texttt{noheadfoot}, \texttt{nofoot}, or
% \texttt{nohead} option to reclaim that space.  As a side efect, these
% options set the page style: \texttt{noheadfoot} implies the \texttt{empty}
% page style, 
% \texttt{nofoot} implies the \texttt{headings} page style, 
% and \texttt{nohead} implies the \texttt{plain} page style.
% Moreover, the \texttt{nofoot} and \texttt{noheadfoot} options disable the
% \texttt{plain} page style\footnote{By making \texttt{plain} synonymous with
% the \texttt{empty} style.} to prevent the \verb:\chapter: command from
% inserting a \verb:\thispagestyle{plain}: command.
%
% The \textsf{twoup} package knows the standard paper size options:
% \texttt{letterpaper}, \texttt{legalpaper}, \texttt{executivepaper},
% \texttt{a4paper}, \texttt{a5paper}, and \texttt{b5paper}.  You should use
% these options as global options to \verb:\documentclass:.  If you print
% two-up on \texttt{legalpaper}, the text width is larger than what is
% considered comfortable.  You should use the \texttt{twocolumn} option to
% \verb:\documentclass: or, better, the \textsf{multicol} package.
%
% The \textsf{twoup} package currently requires that you use dvips to convert
% your .dvi file to postscript.  If you use another .dvi-to-postscript
% program, give
% \textsf{twoup} the \texttt{nospecial} option to suppress the \verb:\special:
% command that \textsf{twoup} will otherwise put in your .dvi file.
%
%
% \section{Installation}
% As you must have figured, you generate the documentation for the
% \textsf{twoup} package by running the file \url:twoup.dtx: through
% \LaTeX---thrice to resolve cross references.\footnote{If you want an index,
%  you must run MakeIndex
% (\texttt{makeindex -s gind.ist twoup}) between the second and third
% \LaTeX{} run.}
%
% To extract the package itself from the .dtx file, run \url:twoup.ins:
% through \LaTeX:
% \begin{quote}
% \verb:latex twoup.ins:
% \end{quote}
% You now have to decide what to do with several files.
% \begin{itemize}
% \item You may have to move the file \url:twoup.sty: to some
% directory where \LaTeX\ can find it; \url:(local)texmf/tex/latex/misc: would be
% the natural choice~\cite{tds}.
% \item Move the documentation, \url:twoup.dvi:, to
% \url:(local)texmf/doc/latex/misc:.
% \item You may discard the source files, \url:twoup.dtx: and
% \url:twoup.ins:, or store them in
% \url:(local)texmf/source/latex/misc:.
% \item Discard all remaining \url:twoup.*: files.
% \end{itemize}
%
%
% \section{Limitations}
% The \textsf{twoup} package is not a pure \LaTeX\ solution but rather a
% prelude to psnup and friends.  If you print your \LaTeX\ documents directly
% from the .dvi file without making a postscript file in the process, you may
% therefore not find \textsf{twoup} particularly useful.
%
% The resulting postscript file makes no pretense of being portable.  Indeed,
% your printer may not recognize the paper size commands that \textsf{twoup}
% recommends that you add to your postscript file.
%
% The current implementation of \textsf{twoup} requires dvips.  This
% limitation is easily overcome with your help: please see code
% line~\ref{line:dvips} and the commentary around it.
%
% The \textsf{twoup} package is designed for and tested on
% \texttt{letterpaper}, \texttt{legalpaper}, and \texttt{a4paper}.  Printing
% two-up on smaller paper is hardly feasible; printing on larger paper is
% beyond the normal desktop printer.
%
% The margins calculated by \textsf{twoup} are too small for
% \verb:\marginpar:s.
%
% If you print two-up on \texttt{legalpaper}, \textsf{twoup} leaves a text
% width larger than what is considered comfortable.  You should use the
% \texttt{twocolumn} option to \verb:\documentclass: or, better, the
% \textsf{multicol} package.
%
% The \textsf{twoup} package is not compatible with the \textsf{geometry}
% package.  Both packages re-calculate the margins and the disagree on the
% interpretation of the paper size options.
%
%
% \section{License}\label{sec:license}
% This program may be distributed and/or modified under the
% conditions of the \LaTeX\ Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   \url;http://www.latex-project.org/lppl.txt;
% and version 1.2 or later is part of all distributions of \LaTeX \
% version 1999/12/01 or later.
%
% This program consists of the files \url:twoup.dtx: and \url:twoup.ins:.
%
%
% \StopEventually{
%    \nocite{ltclass}
%    \bibliographystyle{is-plain}
%    ^^A\bibliography{tex}
%      \begin{thebibliography}{1}
%
%      \bibitem{ltclass}
%      Leslie Lamport, Frank Mittelbach, and Johannes Braams.
%      \newblock {\em Standard Document Classes for \LaTeX\ version 2e}.
%      \newblock CTAN, 1999/09/10 edition, 1999.
%
%      \bibitem{tds}
%      {TUG Working Group on a {\TeX} Directory Structure (TWG-TDS)}.
%      \newblock {\em A Directory Structure for {\TeX} Files}.
%      \newblock CTAN, version 0.9995, January 26, 1998 edition, 1998.
%
%      \end{thebibliography}
%    \PrintIndex
% }
%
% \section{Implementation}
% The \textsf{twoup} package doesn't have to do much---just re-calculate the
% paper size and the margins.  The most difficult part is the advise on how to
% use the psnup program.
% The \textsf{twoup} package does its thing based on the
% plain \LaTeX\ parameters \verb:\paperwidth:,
% \verb:\paperheight:, \verb:\topskip:, and \verb:\baselineskip:.
%
% \subsection{Identification}
% First we must declare ourselves.
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{twoup}[2001/04/03 version 1.1]
%    \end{macrocode}
%
% \subsection{Declaration of Options}
% The \texttt{noheadfoot} option sets the relevant lenghts to zero.  Since
% there is no room for headers or footers, the only sensible page style is
% \texttt{empty}.  The \verb:\chapter: command issues a
% \verb:\thispagestyle{plain}: command, so re-define the \texttt{plain} style
% to be a synonym for the \texttt{empty} style.\footnote{I borrowed the idea
% of brutally making \texttt{plain} a synonym for \texttt{empty} from David
% Carlisle's \textsf{nopageno} package.}
%    \begin{macrocode}
\DeclareOption{noheadfoot}{%
   \setlength{\headheight}{0pt}%
   \setlength{\headsep}{0pt}%
   \setlength{\footskip}{0pt}%
   \let\ps@plain\ps@empty
   \pagestyle{empty}}
%    \end{macrocode}
% With room for a header but without a footer the most sensible page style
% would be \texttt{headings}.  Again the \texttt{plain} page style must be
% disabled.
%    \begin{macrocode}
\DeclareOption{nofoot}{%
   \setlength{\footskip}{0pt}%
   \let\ps@plain\ps@empty
   \pagestyle{headings}}
%    \end{macrocode}
% With room for a footer but no header the most sensible page style is
% \texttt{plain}---so don't change \texttt{plain}.
%    \begin{macrocode}
\DeclareOption{nohead}{%
   \setlength{\headheight}{0pt}%
   \setlength{\headsep}{0pt}%
   \pagestyle{plain}}
%    \end{macrocode}
%
% \begin{macro}{\TwoUp@info}
% \begin{macro}{\TwoUp@paper}
% The paper size options record part of the advise on how to use the psnup
% program in \verb:\TwoUp@info: and part of the advise on how to edit the
% final postscript file in \verb:\TwoUp@paper:.
%    \begin{macrocode}
\DeclareOption{letterpaper}{%
   \def\TwoUp@info{-pletter}%
   \def\TwoUp@paper{letter}}%
\DeclareOption{legalpaper}{%
   \def\TwoUp@info{-plegal}%
   \def\TwoUp@paper{legal}}%
\DeclareOption{executivepaper}{%
   \def\TwoUp@info{-pexecutive}%
   \def\TwoUp@paper{executive}}%
\DeclareOption{a4paper}{%
   \def\TwoUp@info{-pa4}%
   \def\TwoUp@paper{a4}}%
\DeclareOption{a5paper}{%
   \def\TwoUp@info{-pa5}%
   \def\TwoUp@paper{a5}}%
\DeclareOption{b5paper}{%
   \def\TwoUp@info{-pb5}%
   \def\TwoUp@paper{b5}}%
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\TwoUp@special}
% The \textsf{twoup} package needs to record the (smaller) paper size in the
% postscript file.  That means placing a suitable \verb:\special: command in
% the .dvi file.  Unfortunately, ``suitable'' depends on which
% .dvi-to-postscript program you use, so we need an option for each such
% program.  I have implemented the option for dvips but was too lazy to figure
% out the appropriate command for other .dvi-to-postscript
% programs.\nextlinelabel[2]{line:dvips}
%    \begin{macrocode}
\DeclareOption{dvips}{%
   \def\TwoUp@special{%
      \special{papersize=\the\paperwidth,\the\paperheight}}}
%    \end{macrocode}
% If you
% need to use the \textsf{twoup} package with another postscript driver,
% please let me know so I can incorporate more options in future releases
% of \textsf{twoup}.  While you wait for that, use the \texttt{nospecial}
% option to suppress the \verb:\special:.
%    \begin{macrocode}
\DeclareOption{nospecial}{%
   \def\TwoUp@special{\relax}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Execution of Options}
% Default to dvips leaving space for headers and footer as the class sees fit.
%    \begin{macrocode}
\ExecuteOptions{dvips}
\ProcessOptions
%    \end{macrocode}
%
% \subsection{Main Code}
% \subsubsection{Paper Size and psnup Advise}
% \begin{macro}{\TwoUp@info}
% Before re-calculating the paper size, we must record part of the psnup
% advise.  If a paper size option did that already, all is fine.  Otherwise we
% must be printing on the default paper size which we must then determine.  We
% will try to recognize the most common default paper sizes: a4, letter, and
% legal.  Since this is the default paper size, we may assume that the printer
% knows how to handle it.  We therefore suppress the advise on
% editing the final postscript file by \emph{not} defining
% \verb:\TwoUp@paper:
%    \begin{macrocode}
\ifx\TwoUp@info\undefined
   \setlength{\@tempdima}{8.5in}
   \ifdim\paperwidth=\@tempdima
      \setlength{\@tempdima}{11in}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-pletter}
      \fi
      \setlength{\@tempdima}{14in}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-plegal}
      \fi
   \fi
   \setlength{\@tempdima}{210mm}
   \ifdim\paperwidth=\@tempdima
      \setlength{\@tempdima}{297mm}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-pa4}
      \fi
   \fi
\fi
%    \end{macrocode}
% If \verb:\TwoUp@info: is still undefined, we give up and use the \verb:-w:
% and \verb:-h: options to psnup.
%    \begin{macrocode}
\ifx\TwoUp@info\undefined
   \PackageWarningNoLine{twoup}{Unknown paper size.
      You may want to use a \MessageBreak
      paper size option like letterpaper}
%    \end{macrocode}
% \TeX\ displays \verb:\the\paperwidth: as however many \emph{pt}, by
% which \TeX\ means traditional points; one inch is $72.27$\,pt.  However,
% psnup expects the paper width as so-and-so many \emph{pt}, by which psnup
% means postscript points, the unit \TeX\ calls \emph{bp}, or big points; one
% inch is
% $72$\,bp.  To overcome this confusion, we must multiply by
% $\frac{72}{72.27}$ or $0.99627$.
%    \begin{macrocode}
   \setlength{\@tempdima}{0.99627\paperwidth}
%    \end{macrocode}
% The \verb:\@settopoint: command rounds (down) to an integer.  Rounding
% causes the psnup command line to be slightly wrong but less
% ugly.
%    \begin{macrocode}
   \@settopoint\@tempdima
%    \end{macrocode}
% Then record the information in \verb:\TwoUp@info:.  The psnup syntax for the
% output paper size is \verb:-w:\meta{width}
% \verb:-h:\meta{height}.
%    \begin{macrocode}
   \edef\TwoUp@info{-w\the\@tempdima}
%    \end{macrocode}
% Record the paper height in the same manner.
%    \begin{macrocode}
   \setlength{\@tempdima}{0.99627\paperheight}
   \@settopoint\@tempdima
   \edef\TwoUp@info{\TwoUp@info\space -h\the\@tempdima}
\fi
%    \end{macrocode}
% \end{macro}
%
% Now we are ready to change the paper size.  Swap the width and the
% height; then divide the new width by two.
%    \begin{macrocode}
\setlength{\@tempdima}{\paperwidth}
\setlength{\paperwidth}{\paperheight}
\setlength{\paperheight}{\@tempdima}
\setlength{\paperwidth}{0.5\paperwidth}
%    \end{macrocode}
%
% Record the new paper size in the postscript file by placing a suitable
% \verb:\special: command in the .dvi file.
%    \begin{macrocode}
\TwoUp@special
%    \end{macrocode}
%
% \begin{macro}{\TwoUp@info}
% We can now add the new paper size to the list of psnup options.  The psnup
% syntax for the intput paper size is \verb:-W:\meta{width}
% \verb:-H:\meta{height}.  As before, we must correct for the confusion
% between traditional and postscript points.
%    \begin{macrocode}
\setlength{\@tempdima}{0.99627\paperwidth}
\@settopoint\@tempdima
\edef\TwoUp@info{\TwoUp@info\space -W\the\@tempdima}
\setlength{\@tempdima}{0.99627\paperheight}
\@settopoint\@tempdima
\edef\TwoUp@info{\TwoUp@info\space -H\the\@tempdima}
%    \end{macrocode}
% \end{macro}
%
% The advise on psnup options is ready, so ship it out.  Using
% \verb:\PackageInfo: would have been natural, but I want the advise to appear
% on the screen (as well as in the .log file); also the psnup command line is
% rather long, so we need \emph{ad hoc} formatting.
%    \begin{macrocode}
\AtEndDocument{\typeout{^^J%
   Package twoup Info: Use psnup with these options:^^J%
   psnup \TwoUp@info\space -2 \jobname.ps twoup.ps^^J}}
%    \end{macrocode}
%
% If we had an explicit paper size option (indicating that we are to print on
% a paper size other than the default), \verb:\TwoUp@paper: is defined and we
% can give advise on editing the postscript file.
%    \begin{macrocode}
\ifx\TwoUp@paper\undefined\else
   \AtEndDocument{\typeout{^^J%
      Package twoup Info: You may have to add these
      three lines to your .ps file:^^J%
      \@percentchar\@percentchar BeginPaperSize: \TwoUp@paper^^J%
      \TwoUp@paper^^J%
      \@percentchar\@percentchar EndPaperSize^^J}}
\fi
%    \end{macrocode}
%
% \subsubsection{Text Width and Horizontal Margins}
% The standard \LaTeX\ classes~\cite{ltclass} ensure that the line length is
% not too large for comfortable reading.  For two-up printing on
% \texttt{letterpaper}, \texttt{a4paper}, or smaller, that is a non-issue.
% However, \texttt{legalpaper} does leave room for oversized
% lines.\footnote{Up to 25\% ``too large.''} If I leave the line length
% ``small,'' the layout of the two-up printed page looks odd.  I therefore
% allow the oversized lines.  The user should consider using
% \texttt{twocolumn} mode or---better---the \textsf{multicol} package.
%
% I think that a total
% horizontal margin of one inch looks fine.\footnote{Fine enough to just leave
% room (in \texttt{oneside} mode) for the numbers added by the
% \textsf{lineno} package.}  The \verb:\textwidth: is then what is left of the
% \verb:\paperwidth:.
%    \begin{macrocode}
\setlength{\@tempdima}{1in}
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-\@tempdima}
%    \end{macrocode}
% If we are printing in \texttt{twoside} mode, the inner margin should be
% larger than the outer margin.  A ratio of about $1:2$ looks fine.  The outer
% margin is then what is left of the total horizontal margin.
%    \begin{macrocode}
\if@twoside
   \setlength{\evensidemargin}{0.33\@tempdima}
   \setlength{\oddsidemargin}{\@tempdima}
   \addtolength{\oddsidemargin}{-\evensidemargin}
\else
%    \end{macrocode}
% In \texttt{oneside} mode, simply split the margins even.
%    \begin{macrocode}
   \setlength{\oddsidemargin}{0.5\@tempdima}
   \setlength{\evensidemargin}{\oddsidemargin}
\fi
%    \end{macrocode}
% So far we have ignored that the ``real'' left margin is
% \verb:1 inch:${}+{}$\verb:\hoffset:${}+{}$\verb:\oddsidemargin: (or
% \verb:\evensidemargin:).  We must subtract that inch.
%    \begin{macrocode}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\evensidemargin}{-1in}
%    \end{macrocode}
%
% \subsubsection{Text Height and Vertical Margins}
% A top margin of half an inch looks good to me.  As
% a first approximation for the text height, simply subtract all the header
% and footer stuff from the paper height.  (I subtract \verb:\topmargin:
% twice for the sake of the bottom margin.)
%    \begin{macrocode}
\setlength{\topmargin}{0.5in}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-2\topmargin}
\addtolength{\textheight}{-\headheight}
\addtolength{\textheight}{-\headsep}
\addtolength{\textheight}{-\footskip}
%    \end{macrocode}
% The text height must then be corrected to fit an integer number of lines.
% The first line has height \verb:\topskip: while all other lines have height
% \verb:\baselineskip:.  Thus subtract \verb:\topskip: and divide by
% \verb:\baselineskip:.
%    \begin{macrocode}
\addtolength{\textheight}{-\topskip}
\divide\textheight\baselineskip
%    \end{macrocode}
% The \verb:\divide: command performs integer division, so \verb:\textheight:
% is now \meta{number of lines}\,sp.  Store the result in a counter to get a
% \emph{bona fide} number.
%    \begin{macrocode}
\@tempcnta\textheight
%    \end{macrocode}
% Now we can calculate the text height: the correct number of
% \verb:\baselineskip:s plus a \verb:\topskip: for the first line.
%    \begin{macrocode}
\setlength{\textheight}{\@tempcnta\baselineskip}
\addtolength{\textheight}{\topskip}
%    \end{macrocode}
% Again, the ``real'' top margin is
% \verb:1 inch:${}+{}$\verb:\voffset:${}+{}$\verb:\topmargin:,
% so subtract one inch from \verb:\topmargin:.
%    \begin{macrocode}
\addtolength{\topmargin}{-1in}
%</package>
%    \end{macrocode}
% \Finale