%\filename{outputmacros.tex}
%\edited{last by stolfi on Wed May 25 01:05:46 1988}

% Output routine for standard paper format

% TO DO:
%
%   Better suport of paste format (shorten page 1 and 2 by title height,
%   balance last two pages.

\catcode`@=11 \endlinechar=-1

  \message{output ...}

  % Page format parameters

    \newdimen\textwidth % width of text on page
    \newdimen\textheight % height of text on page
    \newdimen\pagewidth % width of page (incl. headers and footers)

  % Global flags and variables (internal)

    \newif\ifprintfilestamp \printfilestamptrue % if T, prints file stamp
    \newif\iffirstpage \firstpagetrue % T on first page of output.
    \newif\ifnewfile   \newfilefalse  % T on first page of a new file.

    \countdef\pageno=0 \pageno=1 % first page is number 1

  % Page header and footer formats

    % \makeheadline builds the header line as a box with
    %   zero height and depth, with all the ink sticking out above it
    
    \def\makeheadline{
      \vbox to 0pt{
        \null\vss
        \hbox to \pagewidth{
          \headerfont
          \iffirstpage \else 
            \hdtitle\hfil\number\pageno 
          \fi
        }
        \vskip 4 pt
        \hrule
        \vskip 3 pt
        \hrule
      }
    }

    % \makefootline builds the footer line as a box with
    %   zero height and depth, with all the ink sticking out below it
    
    \def\copyrightnotice{}  % Redefine this as needed
    
    \def\makefootline{
      \vtop to 0pt{
        \null
        \ifprintfilestamp 
          \ifnewfile 
            \kern30pt
            \hbox to \pagewidth{\relax
              {\smallsize \rm \copyrightnotice}\hfil
              \smallsize\it $[\hbox{\filestamp\lasteditdate\/}]$
            }
            \vss
            \null
          \fi
        \fi
      }
    }

    % \makepagebody combines top and bottom insertions
    %   with the main text into a box of height \vsize and depth 0:

    \def\makepagebody{{\setbox\z@\vbox to\vsize{
          \boxmaxdepth\maxdepth
          \ifvoid\topins\else\unvbox\topins\fi
          \unvbox\@cclv % open up \box255
          \ifvoid\botins\else % footnote info is present
            \vskip\glue\botins
            \kern-0.5\glue\botins
            \hrule width 2truein
            \kern -0.4\p@
            \kern 0.5\glue\botins
            \unvbox\botins
          \fi
        }
        \dp\z@=\z@ \box\z@
      }}

  % \makepage puts header, footer, and page contents together:

  \def\makepage{\vbox{
      \makeheadline
      \kern30pt
      \makepagebody
      \makefootline
    }}

  % Page format

    \output{\plainoutput}

    \def\plainoutput{\offinterlineskip
      \shipout\makepage
      \ifnum\pageno<0
        \global\advance \pageno by -1
      \else
        \global\advance \pageno by 1
      \fi
      \global\newfilefalse
      \global\firstpagefalse
      \ifnum\outputpenalty>-\@MM \else\dosupereject\fi
    }

    \def\dosupereject
      {\ifnum\insertpenalties>\z@ % s.thing is being held over
         \line{}\kern-\topskip\vbreak\forbidden\vfill\supereject\fi}

  % Finalization

    \outer\def\bye{\par\vfill\supereject\end}

\catcode`@=12 \endlinechar=`\^^M

% END


