% Copyright (c) 1989, 1990, 1991 Angus Duggan
% All rights reserved.
% 
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
% 
%     Redistributions of source code must retain the above copyright
%     notice, this list of conditions and the following disclaimer.
% 
%     Redistributions in binary form must reproduce the above copyright
%     notice, this list of conditions and the following disclaimer in the
%     documentation and/or other materials provided with the distribution.
% 
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
% TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
% TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
% PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
% 
% a4mod.sty
% Easily Modifiable a4 page layout. Use this instead of a4 document substyle.
% Provides the macros:
%
%   \setleftmargin{left margin}{rightward shift on odd pages}
%   \setrightmargin{right margin}{leftward shift on even pages}
%   \setheadmargin{top margin}{header height}{header separation}
%   \setfootmargin{bottom margin}{footer height}{footer separation}
%   \setmarginnote{margin note width}{margin note separation}
% 
% Defaults to same size as a4.sty with fullpage option
%
% AJCD, 5/12/89
% AJCD  2/2/90  Changed default size to [a4,fullpage] (1" margins all round)
% AJCD  9/10/91  Added \endinput in case loaded twice
%
\@ifundefined{resetmargins}{}{\endinput}

\typeout{a4mod.sty 2/2/90 -- default size is the same as [a4,fullpage]}

\newlength{\p@perwidth}
\setlength{\p@perwidth}{21 true cm}     % a4 paper width
\newlength{\p@perlength}
\setlength{\p@perlength}{29.7 true cm}  % a4 paper height

\setlength{\voffset}{0 true in}        % shift origin to paper corner
\setlength{\hoffset}{0 true in}

% pick up point size of current font
% these parameters are not changed by the macros below
\newlength{\mainsize}
\setlength{\mainsize}{1\@ptsize pt}
\setlength{\topskip}{\mainsize}	% plain has 10pt
\setlength{\maxdepth}{.4\mainsize}	% plain has 4pt
\setlength{\@maxdepth}{\maxdepth}	% this has to be set as well

\newlength{\leftsidemargin}
\newlength{\leftsideshift}
\newlength{\rightsidemargin}
\newlength{\rightsideshift}
\newlength{\headsidemargin}
\newlength{\footsidemargin}

\let\resetmargins\relax

\def\setleftmargin#1#2{% set left printer margin and odd page shift
  \setlength{\leftsidemargin}{#1}%
  \setlength{\leftsideshift}{#2}%
  \resetmargins
}
%\setleftmargin{1 true in}{.25 true in}
\setleftmargin{1 true in}{0 true in}

\def\setrightmargin#1#2{% set right printer margin and even page shift
  \setlength{\rightsidemargin}{#1}%
  \setlength{\rightsideshift}{#2}%
  \resetmargins
}
%\setrightmargin{1 true in}{.25 true in}
\setrightmargin{1 true in}{0 true in}

\def\setheadmargin#1#2#3{% set head printer margin, size, and separation
  \setlength{\headsidemargin}{#1}%
  \setlength{\headheight}{#2}%
  \setlength{\headsep}{#3}%
  \resetmargins
}
\setheadmargin{1 true in}{\mainsize}{2\mainsize}

\def\setfootmargin#1#2#3{% set foot printer margin, size, and separation
  \setlength{\footsidemargin}{#1}%
  \setlength{\footheight}{#2}%
  \setlength{\footskip}{#3}%
  \addtolength{\footskip}{\footheight}%
  \resetmargins
}
\setfootmargin{1 true in}{\mainsize}{1.5\mainsize}

\def\setmarginnote#1#2{% set marginal note width and separation
  \setlength{\marginparwidth}{#1}%
  \setlength{\marginparsep}{#2}%
  \resetmargins
}
%\setmarginnote{62 pt}{10pt}
\setmarginnote{0 true in}{0 true in}

\def\resetmargins{% reset textheight and length from parameters
  \setlength{\oddsidemargin}{\leftsidemargin}%
  \addtolength{\oddsidemargin}{-1 true in}%
  \addtolength{\oddsidemargin}{\leftsideshift}%
  \setlength{\evensidemargin}{\oddsidemargin}%
  \addtolength{\evensidemargin}{-\rightsideshift}%
  \setlength{\textwidth}{\p@perwidth}% start at full width
  \addtolength{\textwidth}{-\leftsidemargin}%
  \addtolength{\textwidth}{-\leftsideshift}%
  \addtolength{\textwidth}{-\marginparwidth}%
  \addtolength{\textwidth}{-\marginparsep}%
  \addtolength{\textwidth}{-\rightsidemargin}%
  \setlength{\topmargin}{\headsidemargin}%
  \addtolength{\topmargin}{-1 true in}%
  \setlength{\textheight}{\p@perlength}% start at full height
  \addtolength{\textheight}{-\headsidemargin}%
  \addtolength{\textheight}{-\headheight}%
  \addtolength{\textheight}{-\headsep}%
  \addtolength{\textheight}{-\footskip}%
  \addtolength{\textheight}{-\footsidemargin}%
}
\resetmargins
