%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% aapagestruct.sty -- Draws the structure of the page when using
%% pagestyle "pagestruct".
%% 
%% Author          : Anders Andersen
%% Created On      : Thu Jul 18 11:31:37 1996
%% Last Modified By: Anders Andersen
%% Last Modified On: Thu Jul 18 14:28:13 1996
%% Status          : Unknown, Use with caution!
%% 
%% Unless other notices are present in any part of this file
%% explicitly claiming copyrights for other people and/or 
%% organizations, the contents of this file is fully copyright 
%% (C) 1995 Norut IT, all rights reserved. 
%% 
%% Permission is granted to make and distribute verbatim copies 
%% of this document provided that the copyright notice and this
%% permission notice are preserved on all copies.
%% 
%% Permission is granted to copy and distribute modified versions
%% of this document under the conditions for verbatim copying, 
%% provided that the entire resulting derived work is distributed 
%% under the terms of a permission notice identical to this one.
%% 
%% If any other present copyright notices interfere with the 
%% copyright claims above, these claims may be partially overruled 
%% by those notices.
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\def\fileversion{v0.3}
\def\filedate{1996/07/18}
\typeout{Package: `aapagestruct' \fileversion\space <\filedate> (AA)}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{aapagestruct}[\filedate]


% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------

% We will do som calculating, and this is the easiest way
\RequirePackage{calc}


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------

% We need some positions and sizes (counters are used in picture
% environment and are multiplied with \unitlength)

\newlength{\hpicoff}
\newlength{\vpicoff}
\newcounter{hpic@ff}
\newcounter{vpic@ff}

\newlength{\htextpos}
\newlength{\vtextpos}
\newcounter{htextp@s}
\newcounter{vtextp@s}
\newcounter{t@xtwd}
\newcounter{t@xtht}

\newlength{\vheadpos}  % h-pos = htextpos
\newcounter{vheadp@s}
\newcounter{he@dht}
\newlength{\vfootpos}  % h-pos = htextpos
\newcounter{vfootp@s}

\newlength{\hmargpos}  % v-pos = vtextpos
\newcounter{hmargp@s}
\newcounter{m@rgwd}   % ht = t@xtht

% Draw the page structure
\newcommand{\@pstruct}{%
  % Start coordinates for picture env
  \addtolength{\hpicoff}{1in+\hoffset}%
  \setlength{\vpicoff}{\topmargin+\headheight+1in+\voffset}%
  \setcounter{hpic@ff}{\hpicoff/\unitlength}%
  \setcounter{vpic@ff}{\vpicoff/\unitlength}%
  % Head coordinates and sizes
  \setlength{\vheadpos}{\headheight+\topmargin+1in+\voffset}%
  \setcounter{vheadp@s}{\vheadpos/\unitlength}%
  \setcounter{he@dht}{\headheight/\unitlength}%
  % Text coordinates and sizes
  \setlength{\vtextpos}{\vheadpos+\headsep+\textheight}%
  \setcounter{htextp@s}{\htextpos/\unitlength}%
  \setcounter{vtextp@s}{\vtextpos/\unitlength}%
  \setcounter{t@xtwd}{\textwidth/\unitlength}%
  \setcounter{t@xtht}{\textheight/\unitlength}%
  % Foot coordinates and sizes
  \setlength{\vfootpos}{\vtextpos+\footskip}%
  \setcounter{vfootp@s}{\vfootpos/\unitlength}%
  % Marginal notes coordinates and sizes
  \setcounter{hmargp@s}{\hmargpos/\unitlength}%
  \setcounter{m@rgwd}{\marginparwidth/\unitlength}%
  % Draw the page structure
  \begin{picture}(0,0)(\value{hpic@ff},-\value{vpic@ff})
    \thinlines
    % Head
    \put(\value{htextp@s},-\value{vheadp@s}){%
      \framebox(\value{t@xtwd},\value{he@dht}){}}
    % Text
    \put(\value{htextp@s},-\value{vtextp@s}){%
      \framebox(\value{t@xtwd},\value{t@xtht}){}}
    % Foot
    \put(\value{htextp@s},-\value{vfootp@s}){%
      \line(1,0){\value{t@xtwd}}}
    % Marginal note
    \put(\value{hmargp@s},-\value{vtextp@s}){%
      \framebox(\value{m@rgwd},\value{t@xtht}){}}
  \end{picture}}

% Draw the page structure for odd pages
\newcommand{\odd@pstruct}{%
  % Lengths and sizes uniq for odd pages
  \setlength{\hpicoff}{\oddsidemargin}%
  \setlength{\htextpos}{\oddsidemargin+1in+\hoffset}%
  \setlength{\hmargpos}{\htextpos+\textwidth+\marginparsep}%
  \@pstruct}

% Draw the page structure for even pages
\newcommand{\even@pstruct}{%
  % Lengths and sizes uniq for even pages
  \setlength{\hpicoff}{\evensidemargin}%
  \setlength{\htextpos}{\evensidemargin+1in+\hoffset}%
  \setlength{\hmargpos}{\htextpos-\marginparsep-\marginparwidth}%
  \@pstruct}

% Page style showing the structure of the page
\newcommand{\ps@pagestruct}{%
  \renewcommand{\@oddhead}{\odd@pstruct\hfil}%
  \renewcommand{\@oddfoot}{\hfil\textrm{\thepage}\hfil}%
  \renewcommand{\@evenhead}{\even@pstruct\hfil}%
  \renewcommand{\@evenfoot}{\@oddfoot}}
