\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{setarea}[1998/03/16 Hans Friedrich Steffani]

\usepackage{ifthen}
\usepackage{typearea}

\newcounter{divcalc}
\setcounter{divcalc}{6}

% #1 maximal width
% #2 maximal height
\newcommand{\setarea}[2]{%
\typearea{\value{divcalc}}
 \whiledo{ \lengthtest{\textwidth < #1} 
         \and
           \lengthtest{\textheight < #2 } }
{
 \stepcounter{divcalc}
 \typearea{\value{divcalc}}
}
\addtocounter{divcalc}{-1}
\typearea{\value{divcalc}}
}

