%\iffalse
% This is file `scale.dtx'
%
% Please send error reports and suggestions for improvements to
% Soeren Sandmann (sandmann@daimi.au.dk).
%
% copyright (C) 1999  Soeren Sandmann Pedersen
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%
%\fi
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\def\fileversion{v1.1.2}
\def\filedate{1999/08/13}
% \CheckSum{43}
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1994/12/01]
%<package>\ProvidesPackage{scale}
%<package>         [\filedate\space\fileversion]
%<*driver>
\documentclass{ltxdoc}
\begin{document}
   \DocInput{scale.dtx}
\end{document}
%</driver>
% \fi
% \changes{v1.0}{1996/10/09}{Initial version}
% \changes{v1.1}{1998/11/02}{Added support for the magstep2 option. Thanks to
% Rolf Niepraschk (niepraschk@ChbRB.Berlin.PTB.De)}
% \changes{v1.1.1}{1999/05/13}{Released under the GPL}
% \changes{v1.1.2}{1999/08/13}{Fixed a bug that caused an error when running \TeX\ on scale.dtx}
% \title{The \textsf{scale} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{S\o ren Sandmann\\\texttt{sandmann@daimi.au.dk}}
% \date{\filedate}
%
% \maketitle
%
% \begin{abstract}
% This package scales an entire document by either 1.44~(|\magstep2|)
% or by~$\sqrt{2}$.
%
% It is useful if you are writing a document on
% e.g.\ A5 paper and 
% want to print it on A4 paper to achieve better resolution.
% \end{abstract}
%
% \section{Introduction and usage}
% It is sometimes a good idea to scale a document by $\sqrt{2}$.
% This is the case if the output is to be photographically
% reduced. By scaling the document, you will achieve a resolution that is
% approximately $\sqrt{2}$ times better.
%
% Example: You are preparing a document for A5 paper, and your printer
% has a resolution that is 300\,dpi and uses A4 paper. If you use this
% package, your document will be scaled by $\sqrt{2}$. After
% photographical reduction, the resolution will be $\sqrt{2}\cdot
% 300\,\mathrm{dpi}\approx 424\,\mathrm{dpi}$. The package is not restricted
% to A5 paper; it will work with any paper format, simply scaling the
% document by $\sqrt{2}$.
%
% To use use the package, just include it in a |\usepackage{...}|
% statement. Your system must be able to scale your fonts arbitrarily,
% e.g.\ by making them on the fly or by using PostScript fonts.
%
% There is an option to scale the document by |\magstep2| instead of
% $\sqrt{2}$. You might want to use this as it, while not being as
% exact, avoids much of font generation. 
%
% To use this feature use the option `magstep2', like this:
% \begin{quote}
% |\usepackage[magstep2]{scale}|
% \end{quote}
% Thanks to Rolf Niepraschk
% (niepraschk@ChbRB.Berlin.PTB.De) for the code for the above option
% and for some additional cleanups.
%
% The default is to scale by $\sqrt{2}$ 
% \StopEventually{}
%
% \section{The implementation}
% All we need to do is to add a certain length to every margin and set
% |\mag=1414| og |\mag=\magstep2|:
%    \begin{macrocode}
%<*package>
\newcommand\do@scale{}
\DeclareOption{sqrt2}{%
  \renewcommand\do@scale{%
      \typeout{*** scaling: sqrt(2) = 1.414 ***}
      \setlength\@tempdima{0.292893219in}%      (1-(1/sqrt(2)))in 
      \addtolength\oddsidemargin{\@tempdima}
      \addtolength\evensidemargin{\@tempdima}
      \addtolength\topmargin{\@tempdima}
      \mag=1414}
}
%    \end{macrocode}
%
% The magic number 0.292893219 is calculated the following way (using
% |\oddside|\-|margin| as example. Let $o$ be the old |\oddsidemargin|,
% let $h$ be the |\hoffset|, let $i$ be the initial offset (this is always
% $1\,\mathrm{in}$), and let $m$ be the real margin (the one we see on
% the paper). By the primed versions of the variables we mean the `new'
% one; i.e., $o'$ is the new |\oddsidemargin|. We define a function $f$ to
% stand for the application of |\mag=1414|. This function does \emph{not}
% change the initial offset $i$.
%
% The real margin $m$ is calculated as:
%   \[m=i+h+o\]
% We want our new margin to be $\sqrt{2}$ times longer than the old one:
%   \[m'=\sqrt{2}\,m=f(i+h'+o'),\]
% This implies (since $f$ doesn't change $i$) that
%   \begin{eqnarray*}
%     &\sqrt{2}\,m=i + \sqrt{2}\,h' + \sqrt{2}\,o'\\
%     \Longrightarrow\;&o'=
%       {\displaystyle\frac{\sqrt{2}\,m-\sqrt{2}\,h'-i}{\sqrt{2}}}
%       =m-h'-{\displaystyle\frac{1}{\sqrt{2}}}i
%       =i+o+h-h'-{\displaystyle\frac{1}{\sqrt{2}}}i
%   \end{eqnarray*}
% We can just take $h'$ to be the same as $h$ and get
%    \[o'=o+i-\frac{1}{\sqrt{2}}i\approx o+0.292893219\,\mathrm{in}.\]
%
% For the magstep2 option similar calculations give:
%    \begin{macrocode}
\DeclareOption{magstep2}{%   
   \renewcommand\do@scale{%
      \typeout{*** scaling: magstep2 = 1.440 (1.2^2) ***}       
      \setlength\@tempdima{0.305555555555556in}% (1-(1/1.2^2))in 
      \addtolength\oddsidemargin{\@tempdima}
      \addtolength\evensidemargin{\@tempdima}
      \addtolength\topmargin{\@tempdima}
      \mag=\magstep2}
}
%    \end{macrocode}
%
% All we need to do now is to make sqrt2 the default and execute
% |\do@scale| at the beginning of the document:
%    \begin{macrocode}
\ExecuteOptions{sqrt2}
\ProcessOptions
\AtBeginDocument{\do@scale\global\let\do@scale\@empty}
%</package>
%    \end{macrocode}
% \Finale
\endinput
