\typeout{***Threepart headings/footings.  Released 25th February 1988***}
% Three part head and foot macros. 1/87
% Lance Berc
% Olsen & Associates	mcvax!unizh!olsen!lance@seismo.css.gov
% Seefeldstrasse 233
% CH-8008 Zurich
%Extended by W T Hewitt
%
% How users can set the head and foot text.
% either \headings{}{}{} \footings{}{}{}
% or \lhead{}  \chead{} \rhead{}
%    \lfoot{}  \cfoot{} \rfoot{}
% \underon to underline the headings
% \underoff (default) to supress underling of the headings
% 
% Note
% valid arguments might be
% {\rm \protect\thepage}   to get the page number in roman font
% {\leftmark}   to get the section number 
% {\rightmark}   to get the chapter number
%
\newif\if@under\@underfalse
\def\underon{\@undertrue}       % sets underlineing ON
\def\underoff{\@underfalse}     % sets boxing OFF
\def\lhead#1{\gdef\@lhead{#1}} \def\lfoot#1{\gdef\@lfoot{#1}}
\def\chead#1{\gdef\@chead{#1}} \def\cfoot#1{\gdef\@cfoot{#1}}
\def\rhead#1{\gdef\@rhead{#1}} \def\rfoot#1{\gdef\@rfoot{#1}}
%
\def\headings#1#2#3{\gdef\@lhead{#1}\gdef\@chead{#2}\gdef\@rhead{#3}}
\def\footings#1#2#3{\gdef\@lfoot{#1}\gdef\@cfoot{#2}\gdef\@rfoot{#3}}
%
% Initialization of the head and foot text.
% By default the page number is at the center of the foot and everything
% else is empty.
\headings{}{}{}
\footings{}{{\rm \thepage}}{}
%
% Put together a three part header or footer given the left, center and
% right text. The \lap commands put the text into an hbox of zero size,
% so overlapping text is not detected (it just overlaps).
%
\def\@threep#1#2#3{\rlap{#1} \hfil {#2} \hfil \llap{#3}}
%
\def\@threepU#1#2#3{%
\protect\underline{\protect\makebox[\textwidth]{#1 \hfill #2 \hfill #3}}}
%
% Swap the notices on odd and even pages when twosided.
\def\ps@threepart
{\let\@mkboth\markboth
  \def\@oddhead{\if@under\@threepU{\@lhead}{\@chead}{\@rhead}\else
	                 \@threep{\@lhead}{\@chead}{\@rhead}\fi}
   \def\@oddfoot{\@threep{\@lfoot}{\@cfoot}{\@rfoot}}

  \if@twoside
    \def\@evenhead{\if@under \@threepU{\@rhead}{\@chead}{\@lhead}\else
	                     \@threep{\@rhead}{\@chead}{\@lhead}\fi}
    \def\@evenfoot{\@threep{\@rfoot}{\@cfoot}{\@lfoot}}
  \else
     \def\@evenhead{\if@under\@threepU{\@lhead}{\@chead}{\@rhead}\else
   	                     \@threep{\@lhead}{\@chead}{\@rhead}\fi}
      \def\@evenfoot{\@threep{\@lfoot}{\@cfoot}{\@rfoot}}
  \fi
}

%call ps@headings to get section/chapter commands defined to use \markboth etc
\ps@headings
% Default page style
\ps@threepart
