% SETPAGEDIMS DOCUMENT STYLE
% Last edited on 2010-03-12 20:56:36 by stolfi
% Based on largepages.sty for LaTeX 2.09
% By Pedro J. de Rezende.
%
% \usepackage{setpagedims} defines the macros
% \setpapersize and \settextsize that reset the 
% paper and text dimensions.
%
\typeout{Document Style Option `setpagedims' -- Version of 2001-10-12}

% Usage: \setpapersize{WIDTH}{HEIGHT}
%
\newcommand{\setpapersize}[2]{
  \paperwidth=#1\relax
  \paperheight=#2\relax
  % Inform dvips about the paper dimensions:
  \special{papersize=#1,#2}
}

% Usage: \settextsize{WIDTH}{HEIGHT}
%
\newcommand{\settextsize}[2]{

  \textwidth=#1\relax
  \textheight=#2\relax

  % FIX HORIZONTAL MARGINS
  
  \oddsidemargin=\paperwidth\relax

  % Divide the space evenly between left and right margins:
  \advance\oddsidemargin by-#1\relax
  \divide\oddsidemargin by 2\relax
  
  % Tex \oddsidemargin and \evensidemargin are measured 
  % from 1 inch at right of the left paper edge:
  \advance\oddsidemargin by-1in\relax
  
  % If single-side printing, the margins are all equal:
  \evensidemargin=\oddsidemargin\relax
  
  \if@twoside
    % Shift pages left or right:
    \advance\oddsidemargin by -18pt
    \advance\evensidemargin by 18pt
  \fi

  % Recompute \marginparwidth and \marginparsep.
  % Try to use all of \evensidemargin minus
  % \marginparsep on one side and 10pt on the other side.
  % Note that \evensidemargin is counted 1in from the edge.
  \marginparwidth=\evensidemargin\relax
  \advance \marginparwidth by 1in 
  \advance\marginparwidth by -\marginparsep
  \advance\marginparwidth by -10pt
  \ifdim\marginparwidth<25pt
     \marginparwidth=25pt
  \fi
  
  % FIX VERTICAL MARGINS

  % Divide space evenly between top and bottom margins.
  % Headers are assumed to be inside the top margin.
  % Footers are assumed to be inside the bottom margin.
  \topmargin=\paperheight\relax
  \advance\topmargin by-#2\relax
  \divide\topmargin by 2\relax
  \advance\topmargin by-\headheight\relax
  \advance\topmargin by-\headsep\relax

  % Tex \topmargin is measured from 1 inch below the paper edge:
  \advance\topmargin by -1in\relax

}



