%\iffalse
%
% file: autofilo.dtx
% Copyright (C) 1997 by Frank Bennett.  All rights reserved.
%
% IMPORTANT NOTICE:
% 
% You are not allowed to change this file.  You may however copy
% this file to a file with a different name and then change the
% copy if (a) you do not charge for the modified code, (b) you
% acknowledge the author of this file in the new file, if it
% is distributed to others, and (c) you attach these same
% conditions to the new file.
% 
% You are not allowed to distribute this file alone.  You are not
% allowed to take money for the distribution or use of this file
% (or a changed version) except for a nominal charge for copying
% etc.
% 
% You are allowed to distribute this file under the condition that
% it is distributed with all of its contents, intact.
% 
% For error reports, or offers to help make this a more powerful,
% friendlier, and altogether more thrilling package, please contact me on
% fb@soas.ac.uk.  Better yet, make a contribution to
% my pension.  Account details available on request.
%
%\fi
%
% \def\fileversion{3.1.1.1}
% \def\filedate{1998/01/17 18:13:42}
%
% \iffalse
%
%<*driver>
\documentclass{ltxdoc}
%\CodelineIndex
%\EnableCrossrefs
\begin{document}
\OnlyDescription    % Comment out for implementation details
\DocInput{autofilo.dtx}
\end{document}
%</driver>
%\fi
%
%\iffalse
% Source tree moved under RCS
% ---------------------------
% autofilo.dtx,v
% Revision 3.1.1.1  1998/01/17 18:13:42  root
% Release code, checksum verified
%
% Revision 3.1  1998/01/17 16:56:58  root
% Release code
%
% Revision 2.8  1998/01/16 11:52:55  root
% *** empty log message ***
%
% Revision 2.7  1998/01/15 10:45:24  root
% Filofax page now comes out centered on the physical page.
% Just fold the thing in half and cut.
%
% Revision 2.6  1997/12/05 17:01:48  root
% Added zero width vrule to force left-hand cut rule to right
% position even when jawline has no width.
%
% Revision 2.5  1997/12/05 13:47:40  root
% Fixed quandary of overlapping revisions.
%
% Revision 2.4  1997/12/05 12:14:08  root
% Fixed missing brace in af@circle, and added RequirePackage
% for keyval parser.
% Revision 2.2.1.5  1997/11/26 11:07:51  bennett
% Final change to documentation.
%
% Revision 2.2.1.4  1997/11/07 16:27:06  root
% Fixed checksum, added some documentation for the jawmarks
% code.
%
% Revision 2.2.1.3  1997/11/07 16:15:14  root
% Final fixes to jawmark code, maybe.
%
% Revision 2.2.1.2  1997/11/07 16:10:59  root
% Patched up code for jaw marks.
%
% Revision 2.2.1.1  1997/11/07 14:57:37  root
% Trial code for jaw marks.
%
% Revision 2.4  1997/12/05 12:14:08  root
% Fixed missing brace in af@circle, and added RequirePackage
% for keyval parser.
%
% Revision 2.3  1997/11/07 14:52:50  root
% Added trial code for jaw marks.
%
% Revision 2.2  1997/11/07 10:44:05  root
% Release code.
%
% Revision 2.1.1.1  1997/11/04 05:06:07  root
% Development branch
%
% Revision 2.1  1997/11/01 15:17:06  bennett
% Release code.
%
% Revision 1.2  1997/10/29 20:03:07  bennett
% *** empty log message ***
%
% Revision 1.1  1997/10/29 08:17:52  root
% Initial revision
%
%\fi
%
% \title{User's Guide to the \texttt{autofilo} 
%    package\thanks{This file is version number
%    \fileversion{}.  It was last revised on
%    \filedate{}.}}
%
% \author{Frank G. Bennett, Jr.}
%
% \maketitle
%
% \setcounter{StandardModuleDepth}{1}
% \DeleteShortVerb{\|}
% \MakeShortVerb{\"}
%
% \begin{abstract}
% \noindent This package provides an environment
% within which pages are framed with cut lines and
% printed with punch-marks, so that printed text can
% easily be inserted into a filofax or binder.
% \end{abstract}
%
% \CheckSum{692}
%
% \section{About the Style}
%
% This style provides a rough solution to the design
% problem it addresses, but it does work.  Pages are
% always printed in landscape, rotated using the "lscape"
% package from the "graphics" bundle, and centered on the
% physical paper.\footnote{As a technical note, the frame itself
% is not rotated, because it is inserted independently of
% the output boxes controlled by the \LaTeX{} output routine.
% The output modes (two-column,
% and a hacked-together four-column mode) have
% been modified to understand blocks of text as \cs{hbox}es
% to be laid atop one another, rather than as \cs{vbox}es
% to be set alongside one another.}  It accepts two options,
% "twocolumn" (the default) and "fourcolumn".
%
% The style provides an environment called "autofilo".
% Most often, users of this package will be style
% authors who want to incorporate it into other
% environments that do more specific things.  Because
% "autofilo" accepts several "keyval"-style parameters,
% style authors may have a use for documentation for those
% optional parameters.  So here is some sample documentation:
%
% \begin{description}
% \item[\texttt{punchcluster}] Most filofaxes have two or
%   or more clusters or groups of punches to hold the
%   pages in place.  This option sets the number of punches
%   in each cluster.  The default is three.
% \item[\texttt{intraspace}]  This governs the space
%   between punchouts within a group.  The default is
%   19.25mm.
% \item[\texttt{punchgroups}] This option sets the number
%   of groups of punches.  The default is two groups.
% \item[\texttt{interspace}]  This option sets the
%   distance between the groups of punches.  The default
%   is 51.25mm.
% \item[\texttt{pageheight}]  This fixes the height
%   of a filofax page (not the physical paper on
%   which it is printed).  The default is 172mm.
% \item[\texttt{pagewidth}]  This fixes the width of an individual
%   page.  The physical printed area will be twice this figure.
%   The default is 95mm, for a 190mm printed area. 
% \item[\texttt{grip}]  This adjusts the distance from the
%   edge of the page to the outer edge of the punchouts.
%   Defaults to 5mm.
% \item[\texttt{punchmargin}]  This adjusts the distance from the
%   edge of the text to the inner edge of the punchouts.
%   Defaults to 2mm.
% \item[\texttt{punchsize}]  Size, in points, of punchouts.
%   Defaults to 15.
% \item[\texttt{topspace}]  Gap between top of filofax page
%   and top of text page.
% \item[\texttt{bottomspace}]  Gap between bottom of filofax page
%   and bottom of text page.
% \item[\texttt{jawspread}] If set to a positive length, this places a set
%   of rules the width of the punchmarks on either side of each
%   punchhole, centered on its center and spread the distance specified.
%   This can be useful as a guide with some one-hole punches that are
%   designed to be used ``blind''.
% \item[\texttt{jawline}] Sets the width of the lines used to make
%   jawmarks.  The default value is \texttt{0.4pt}.
% \end{description}
%
% \StopEventually{\PrintIndex}
%
% \section{The Class File}
%
%    \begin{macrocode}
%<*style>
\NeedsTeXFormat{LaTeX2e}[1995/06/01]
\ProvidesPackage{autofilo}
          [1997/12/05 12:14:08 2.4 Filofax page outlines (Frank Bennett)]
%    \end{macrocode}
% We need a boolean to process our sole option.
%    \begin{macrocode}
\newif\if@usequadruplecolumn
%    \end{macrocode}
% We provide four columns as an option.  Two columns (one for
% each side of what will be the filofax page) will be the
% default.
%    \begin{macrocode}
\DeclareOption{fourcolumn}{\@usequadruplecolumntrue}
%    \end{macrocode}
% Process the option if present, and load a supporting package.
%    \begin{macrocode}
\ProcessOptions
\RequirePackage{lscape}
\RequirePackage{keyval}
%    \end{macrocode}
% Declare some variables.
%    \begin{macrocode}
\newif\if@quadruplecolumn
\newbox\@leftleftcolumn
\newbox\@leftrightcolumn
\newbox\@rightleftcolumn
\newbox\@rightrightcolumn
\newcount\af@punchcluster
\newcount\af@punchgroups
\newlength\af@interspace
\newlength\af@intraspace
\newlength\af@grip
\newlength\af@punchmargin
\newcount\af@punchsize
\newlength\af@punchwidth
\newlength\af@halfpunchwidth
\newcount\af@subtempcount
\newcount\af@tempcount
\newlength\af@textwidth
\newlength\af@marginrel
\newlength\af@halftextwidth
\newlength\af@textheight
\newlength\af@topmargin
\newlength\af@bottommargin
\newcount\col@no
\newlength\af@jawspread
\newlength\af@halfjawspread
\newlength\af@jawline
%    \end{macrocode}
% We'll need a macro to turn on the four-column mode.
% This is just a modified version of \cs{twocolumn} in
% the \LaTeX{} distribution.
%    \begin{macrocode}
\def\quadruplecolumn{%
  \clearpage
  \global\columnwidth\textwidth
  \global\advance\columnwidth-3\columnsep
  \global\divide\columnwidth by4\relax
  \global\hsize\columnwidth
  \global\linewidth\columnwidth
  \global\@twocolumntrue
  \global\@quadruplecolumntrue
  \global\@firstcolumntrue
  \col@number=4\relax}
%    \end{macrocode}
% Catch the output routine when the new mode is in effect.
%    \begin{macrocode}
\def \@opcol {%
  \if@twocolumn
    \if@quadruplecolumn
      \@outputqdrplcol
    \else
      \@outputdblcol
    \fi
  \else
    \@outputpage
  \fi
  \global \@mparbottom \z@ \global \@textfloatsheight \z@
  \@floatplacement}
%    \end{macrocode}
% Add a new output routine for the new mode, and a modified
% version of the two-column output routine.  Note that these
% work \textit{only} inside the \texttt{landscape} environment.
%    \begin{macrocode}
\def\@outputqdrplcol{%
  \ifcase\col@no
    \global\@firstcolumnfalse
    \global \setbox\@leftleftcolumn \box\@outputbox
  \or
    \global \setbox\@leftrightcolumn \box\@outputbox
  \or
    \global \setbox\@rightleftcolumn \box\@outputbox
  \or
    \global \@firstcolumntrue
    \global\setbox\@rightrightcolumn\box\@outputbox
    \setbox\@outputbox \vbox to\textwidth{%
                           \hb@xt@\textheight {%
         \vrule height\columnwidth depth0pt width0pt
                          \box\@rightrightcolumn \hss}%
                           \vfill
                           \hrule \@width\columnseprule
                           \vfill
                         \hb@xt@\textheight {%
         \vrule height\columnwidth depth0pt width0pt
                             \box\@rightleftcolumn \hss}%
                           \vfill
                           \hrule \@width\columnseprule
                           \vfill
                         \hb@xt@\textheight {%
         \vrule height\columnwidth depth0pt width0pt
                             \box\@leftrightcolumn \hss}%
                           \vfill
                           \hrule \@width\columnseprule
                           \vfill
                         \hb@xt@\textheight {%
                             \box\@leftleftcolumn \hss}%
                              }%
    \@combinedblfloats
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
  \fi
  \global\advance\col@no by1\relax
  \ifnum\col@no=4\relax\global\col@no=0\fi}
\def\@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global \setbox\@leftcolumn \box\@outputbox
  \else
    \global \@firstcolumntrue
    \setbox\@outputbox \vbox to\textwidth{%
                         \hbox to\textheight{%
                             \box\@outputbox}%
                           \vfil
                           \hrule \@width\columnseprule
                           \vfil
                           \hbox to\textheight{%
                             \box\@leftcolumn}}%
    \@combinedblfloats
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
  \fi
}
%    \end{macrocode}
% We use circles to make punchmarks.
% When making circles, \TeX{} will put the center of the
% circle at point, but consume horizontal space equal
% to the full diameter of the circle.  To compensate,
% we need to skip forward by radius, and back again
% after laying each circle.
%    \begin{macrocode}
\def\af@circle{\hbox{\hskip\af@halfpunchwidth%
                     \ifnum\af@jawspread>0\relax%
                       \hskip-\af@halfjawspread%
                       \hskip-\af@jawline%
                         \vrule depth\af@halfpunchwidth%
                                height\af@halfpunchwidth%
                                width\af@jawline%
                       \hskip\af@halfjawspread%
                     \else%
                       \vrule depth\af@halfpunchwidth%
                              height\af@halfpunchwidth%
                              width0pt%
                     \fi%
                     \circle{\af@punchsize}%
                     \hskip-\af@punchwidth%
                     \ifnum\af@jawspread>0\relax%
                       \hskip\af@halfjawspread%
                         \vrule depth\af@halfpunchwidth%
                                height\af@halfpunchwidth
                                width\af@jawline%
                       \hskip-\af@halfjawspread%
                       \hskip-\af@jawline%
                     \fi%
                     \hskip-\af@halfpunchwidth}}
%    \end{macrocode}
% We define a looping command that lays down a cluster
% of circles.  Grouping allows this loop to be nested
% in another.
%    \begin{macrocode}
\def\af@group{%
  \bgroup%
    \af@tempcount=0%
    \af@circle%
    \loop\advance\af@tempcount by1\relax%
    \ifnum\af@tempcount<\af@punchcluster%
      \hskip\af@intraspace\relax\af@circle%
    \repeat%
  \egroup}
%    \end{macrocode}
% We define a command that lays down a set of clusters
% (groups).
%    \begin{macrocode}
\def\af@circles{%
  \af@tempcount=0\relax%
  \af@group%
  \loop\advance\af@tempcount by1\relax%
  \ifnum\af@tempcount<\af@punchgroups%
    \hskip\af@interspace\relax\af@group%
  \repeat%
  \af@tempcount=0}
%    \end{macrocode}
% The following command creates a set of punchmarks.
%    \begin{macrocode}
\def\af@punches{%
  \hbox to\af@textheight{\hfil\af@circles\hskip\af@halfpunchwidth\relax\hfil}}
%    \end{macrocode}
% The following creates a frame.  The model was lifted from the "geometry"
% package.
%    \begin{macrocode}
\def\@@@innerframe{%
  \moveright-\af@topmargin%
  \vbox to 0pt{%
    \vskip\topmargin%
    \vbox to0pt{\hrule width\af@textheight\vss}%
    \hbox to\af@textheight{\llap{\vrule height\af@textwidth}%
      \hfil\vrule height\af@textwidth}%
    \vskip-\af@halftextwidth%
    \vbox to0pt{\hrule width\af@textheight\vss}%
    \vskip-\af@halftextwidth%
    \vskip\af@grip%
    \nointerlineskip\af@punches\nointerlineskip%
    \vskip-\af@punchwidth%
    \vskip-\af@grip%
    \vskip\af@textwidth%
    \vskip-\af@punchwidth%
    \vskip-\af@grip%
    \nointerlineskip\af@punches\nointerlineskip%
    \vskip\af@grip%
    \vbox to0pt{\hrule width\af@textheight\vss}%
    \vss}}%
%    \end{macrocode}
% A further modification of the output routine,
% this time to put the frame in place.  This, too, is
% lifted from "geometry".  It has been modified only
% slightly, but we drop \LaTeX 2.09 support altogether.
%    \begin{macrocode}
\newif\if@latextwoe
\@ifundefined{if@compatibility}{\@latextwoefalse}{\@latextwoetrue}
\if@latextwoe
\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \let \protect \noexpand
  \@resetactivechars
  \let\-\@dischyph
  \let\'\@acci\let\`\@accii\let\=\@acciii
  \let\\\@normalcr
  \let\par\@@par          %% 15 Sep 87
  \shipout \vbox{%
    \set@typeset@protect
    \aftergroup \endgroup
    \aftergroup \set@typeset@protect
  \if@specialpage
    \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
  \fi
  \if@twoside
    \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
         \let\@themargin\oddsidemargin
    \else \let\@thehead\@evenhead
       \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
    \fi
  \fi
  \reset@font
  \normalsize
  \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
    \@begindvi
    \moveright\@themargin %<<<<<<<<<<<<<<<<<<<<< added
    \vtop{\@@@innerframe  %<<<<<<<<<<<<<<<<<<<<< added
    \vskip \topmargin
    \vskip \af@marginrel
%  \moveright\@themargin \vbox OPENBRACE %<<<<<<<<<<<< original
      \moveright\af@topmargin%     <<<<<<<<<<<< Bennett
      \vbox{%             %<<<<<<<<<<<<<<<<<<<<< modified
      \setbox\@tempboxa \vbox to\headheight{%
        \vfil
        \color@hbox
          \normalcolor
          \hb@xt@\textwidth {%
            \let \label \@gobble
            \let \index \@gobble
            \let \glossary \@gobble %% 21 Jun 91
            \@thehead
            }%
        \color@endbox
        }%                        %% 22 Feb 87
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \box\@outputbox
      \baselineskip \footskip
      \color@hbox
        \normalcolor
        \hb@xt@\textwidth{%
          \let \label \@gobble
          \let \index \@gobble      %% 22 Feb 87
          \let \glossary \@gobble   %% 21 Jun 91
          \@thefoot
          }%
      \color@endbox
      }}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< One more close bracket added 
    }%
\global \@colht \textheight
\stepcounter{page}%
\let\firstmark\botmark
}
\else
\message{Sorry, autofilo.sty works only with LaTeX2e}
\fi
%    \end{macrocode}
% Set some global parameters.
%    \begin{macrocode}
\headheight=0pt
\headsep=0pt
\footskip=0pt
\marginparwidth=0pt
\marginparsep=0pt
\pagestyle{empty}
\parindent=0pt
\raggedbottom
\columnseprule=0.0pt%
\raggedright
%    \end{macrocode}
% Some option definitions.
%    \begin{macrocode}
\define@key{opt}{pageheight}{%
  \af@textheight=#1\relax}
\define@key{opt}{pagewidth}{%
  \af@halftextwidth=#1\relax}
\define@key{opt}{columnsep}{%
  \columnsep=#1\relax}
\define@key{opt}{punchcluster}{%
  \af@punchcluster=#1}
\define@key{opt}{punchgroups}{%
  \af@punchgroups=#1}
\define@key{opt}{interspace}{%
  \af@interspace=#1}
\define@key{opt}{intraspace}{%
  \af@intraspace=#1}
\define@key{opt}{grip}{%
  \af@grip=#1}
\define@key{opt}{punchmargin}{%
  \af@punchmargin=#1}
\define@key{opt}{punchpoints}{%
  \af@punchsize=#1}
\define@key{opt}{topspace}{%
  \af@topmargin=#1}
\define@key{opt}{bottomspace}{%
  \af@bottommargin=#1}
\define@key{opt}{jawspread}{%
  \af@jawspread=#1}
\define@key{opt}{jawline}{%
  \af@jawline=#1}
%    \end{macrocode}
% The default values for the options.
%    \begin{macrocode}
\af@textheight=172mm
\af@halftextwidth=95mm
\columnsep=14pt
\af@punchcluster=3
\af@punchgroups=2
\af@interspace=51.25mm
\af@intraspace=19.25mm
\af@grip=5mm
\af@punchmargin=2mm
\af@punchsize=15
\af@topmargin=2pt
\af@bottommargin=0pt\relax
\af@jawline=0.4pt%
%    \end{macrocode}
% The remaining dimensions must be calculated inside
% the landscape environment.  We define that now.
%    \begin{macrocode}
\def\autofilo#1{%
  \setkeys{opt}{#1}%
  \oddsidemargin=-1in\relax%
   \af@textwidth\paperwidth%
   \advance\af@textwidth by-\af@textheight%
   \divide\af@textwidth by2\relax%
   \advance\oddsidemargin by\af@textwidth%
  \evensidemargin=-1in\relax%
   \advance\evensidemargin by\af@textwidth%
  \topmargin=-1in\relax%
   \af@textwidth\paperheight%
   \advance\af@textwidth by-\af@halftextwidth%
   \advance\af@textwidth by-\af@halftextwidth%
   \divide\af@textwidth by2\relax%
   \advance\topmargin by\af@textwidth\relax%
  \landscape%
  \af@halfjawspread\af@jawspread%
  \divide\af@halfjawspread by2\relax%
  \af@punchwidth=\af@punchsize pt%
  \af@halfpunchwidth\af@punchwidth%
  \divide\af@halfpunchwidth by2%
  \textheight\af@textheight%
  \advance\textheight by-\af@topmargin%
  \advance\textheight by-\af@bottommargin%
  \af@textwidth\af@halftextwidth%
  \multiply\af@textwidth by2\relax%
  \textwidth=\af@textwidth%
  \advance\textwidth by-2\af@punchwidth%
  \advance\textwidth by-2\af@grip%
  \advance\textwidth by-2\af@punchmargin%
  \af@marginrel\af@grip%
  \advance\af@marginrel by\af@punchmargin%
  \advance\af@marginrel by\af@punchwidth%
  \vsize\textheight%
  \hsize\textwidth%
  \@colroom\vsize%
  \@colht\vsize%
  \if@usequadruplecolumn%
    \quadruplecolumn%
  \else%
    \twocolumn%
  \fi}
%    \end{macrocode}
% The end of the environment is a simple thing.
%    \begin{macrocode}
\def\endautofilo{%
  \endlandscape}
%</style>
%    \end{macrocode}
% \Finale \PrintChanges





