% ^^A -*- latex -*-
%
% \iffalse
%
%% File: margins.dtx Copyright (C) 1997 Yann Dirson
%%
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{margins}
%<package>         [1997/09/11 Custom-sized margins support]
%
%<*driver>
\documentclass{ltxdoc}
%\GetFileInfo{margins.sty}
\newcommand\fileversion{0.3} \newcommand\filedate{1 Jul 1997}
\RecordChanges
\begin{document}
\title{The \textsf{margins} package\thanks{This file
	 has version number \fileversion, last
	 revised \filedate.}}
\author{Yann Dirson\\dirson@univ-mlv.fr}
\date{\filedate}
\maketitle
\DeleteShortVerb{\|}
\DocInput{margins.dtx} \PrintChanges
\end{document}
%</driver>
% \fi
%
% \CheckSum{49}
%
% \changes{v0.1}{1997/06/27}{Initial revision}
% \changes{v0.2}{1997/07/01}{More documentaion; some fixes}
% \changes{v0.3}{1997/09/11}{Added package options "nomarginpars",
%   "nopageheaders", "nopagefooters", and "full".}
%
% \MakeShortVerb{\"}
%
% \begin{abstract}
% This package allow the user to set his own margins.
%
% It is for now mainly featureless, and there are many things to improve.
% Fell free to mail the author with suggestions, bug-reports, patches, 
% virtual beer, etc.
% \end{abstract}
%
% \section{Package options}
%
% By default, the "\marginpar{text}" command allows to typeset "text" in a
% marginal note. However, when no marginal notes are used, the marginal space
% reserved for them is wasted, and it can be useful to reduce it to 0.
%
% The "nomarginpars" option can be used to have this space used, and to
% disable the "marginpar" command to prevent from using it when there's no
% space for its work.
%
%    \begin{macrocode}
\DeclareOption{nomarginpars}{%
  \setlength{\marginparsep}{0mm}%
  \setlength{\marginparwidth}{0mm}%
  \renewcommand{\marginpar}[1]{%
    \message{margins.sty: ignoring \marginpar, which cannot be used together%
      with the ``nomarginpars'' option}%
    }%
  }%
%    \end{macrocode}
%
% The same comment holds for page headers and footers to optimize use of
% horizontal space.
%
% Page headers make use of I-don't-know-which macros, which sould be disabled
% when found.
%
%    \begin{macrocode}
\DeclareOption{nopageheaders}{%
  \setlength{\headheight}{0mm}%
  \setlength{\headsep}{0mm}%
  }%  
%    \end{macrocode}
%
% Page footers make use of the "\pagestyle" macro.
%
%    \begin{macrocode}
\DeclareOption{nopagefooters}{%
  \pagestyle{empty}%
  \setlength{\footskip}{0mm}%
  }%  
%    \end{macrocode}
%
% One might want to get the largest available printable area with one option.
% "full" will call all available macros.
%
%    \begin{macrocode}
\DeclareOption{full}{%
  \ExecuteOptions{nomarginpars,nopageheaders,nopagefooters}%
  }%
%    \end{macrocode}
%
% Options are then processed. No default options are explicitely called,
% because none of them can be reverted.
%  
%    \begin{macrocode}
\ProcessOptions%
%    \end{macrocode}
%
% \section{Package commands}
%
% "\sethmargins{width}" sets horizontal margins to "width";
% "\setvmargins{height}" sets vertical margins to "height".
%
% By default, on package inclusion, both horizontal and vertical margins are
% set to a length of "20mm".
%
% \StopEventually{}
%
% \section{The Macros}
%
% \subsection{Setting horizontal space}
%
% \DescribeMacro{\sethmargins}
% The "\sethmargins" macro changes the "\hoffset" and "\textwidth" lengths
% to equilibrate both right and left margins to the given value.
%
% There is only one mandatory argument:
%
%    \begin{macrocode}
\newcommand{\sethmargins}[1]{%
%    \end{macrocode}
%  
% Both sides' "sidemargin" lengths are set to 0. Maybe this should be
% changed, but I don't have any idea of the way we should handle them. If
% anybody has any idea for this, just mail the author.
%  
%    \begin{macrocode}
  \setlength{\oddsidemargin}{0mm}%
  \setlength{\evensidemargin}{0mm}%
%    \end{macrocode}
%  
% Each length is gradually computed. "\hoffset" is initialized to forget the
% systematically ``wasted'' first inch of paper:
%  
%    \begin{macrocode}
  \setlength{\hoffset}{-1in}%
%    \end{macrocode}
%  
% Then we just have to increment it by the width we're looking for to set the
% right margin:
%  
%    \begin{macrocode}
  \addtolength{\hoffset}{#1}%
%    \end{macrocode}
%  
% Similarily, we initially set "\paperwidth" to the full width of paper,
% before substracting both margins:
%  
%    \begin{macrocode}
  \setlength{\textwidth}{\paperwidth}%
  \addtolength{\textwidth}{-#1}%
  \addtolength{\textwidth}{-#1}%
%    \end{macrocode}
%  
% We also have to substract the width occupied by marginpars:
%  
%    \begin{macrocode}
  \addtolength{\textwidth}{-\marginparsep}%
  \addtolength{\textwidth}{-\marginparwidth}%
  }
%    \end{macrocode}
%
% \subsection{Setting vertical space}
%
% \DescribeMacro{\setvmargins}
% The "\setvmargins" macro works quite the same way as "\sethmargins"
%
%    \begin{macrocode}
\newcommand{\setvmargins}[1]{%
  \setlength{\topmargin}{0mm}%
  \setlength{\voffset}{-1in}%
  \addtolength{\voffset}{#1}%
  \setlength{\textheight}{\paperheight}%
  \addtolength{\textheight}{-#1}%
  \addtolength{\textheight}{-#1}%
%    \end{macrocode}
%  
% Here for "\textheight" we need to substract the reserved space for headers
% and footers:
%  
%    \begin{macrocode}
  \addtolength{\textheight}{-\footskip}%
  \addtolength{\textheight}{-\headheight}%
  \addtolength{\textheight}{-\headsep}%
  }%
%    \end{macrocode}
%
% \section{Package initialization}
%
% The document's margins are then automagically set to "20mm" on load:
%
%    \begin{macrocode}
\sethmargins{20mm}%
\setvmargins{20mm}%
%    \end{macrocode}
%
% \Finale
\endinput
