% \changes{v1.1}{28 Jan 96}{First release}
% \CheckSum{202}
%
% \iffalse meta-comment
%
% File: booklet.dtx
% Options: 
% Written by Nick Urbanik, 28 Jan 96
% An example of its use:
%
%\documentclass{booklet}
%
% To use this template:
% search for the following:
% FILENAME, ACTION, EXAMPLE, 28 Jan 96, 28 January 96, 1996/01/28,
% PURPOSE, FIRSTOPTION, BASE, DEFAULTOPTIONS, 
% $Header: F:\EMTEX\TEXINPUT\LATEX2E\NICK\RCS\booklet.dtx 1.2 1996/03/04 12:15:30 Nick Exp Nick $
%
% $Log: booklet.dtx $
% Revision 1.2  1996/03/04  12:15:30  Nick
% This version is from home.  IT provides parameterised base class.
% However, the version from work, the previous version, has some typos fixed,
% and some other documentation.  I really need to rcsmerge them together.
%
%
% \fi
%
% \begin{abstract}
%
% \end{abstract}
%
% \tableofcontents
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{How to use this class}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The best way to see how to use this is by example.  See the file
% \texttt{learnc.tex} for a complete example.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Options available}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%\StopEventually{}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{The implementation}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Producing the documentation}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Here is a short driver program that can be extracted with the \LaTeXe
% \textsf{docstrip} program.  It is not necessary to create a separate
% driver file from this, however; you can just run \emph{this}
% file, \file{booklet.dtx} through \LaTeXe.
%
%    \begin{macrocode}
%<*driver>
\ProvidesFile{booklet.drv}
\documentclass[a4paper,twoside]{ltxdoc}
\usepackage{a4,fancyheadings}
%    \end{macrocode}
% I have had problems with getting the correct |\filedate| and |\fileversion|
% from this file.  I keep getting them from the file \file{a4.sty}.
% I believe the next line is supposed to fix such a problem, but it
% leaves them undefined.
%    \begin{macrocode}
% \GetFileInfo{booklet.dtx}
%    \end{macrocode}
% This is definitely the wrong place to put |\fileversion|,
% |\fileversion| and |\docdate|, since it is hard
% to find them here, but at the moment it's the only place where I can get
% them to work!
%    \begin{macrocode}
\def\fileversion{2.0f}
\def\filedate{28 January 96}
\def\docdate{28 January 96}
%    \end{macrocode}
% These depend on the package |fancyheadings|.  If you don't have it, you
% may want to comment out these lines.  You may prefer to comment out the
% line |\thispagestyle{empty}| further down.
%    \begin{macrocode}
\pagestyle{fancy} \lhead[\textbf{\upshape The file
  \texttt{booklet.dtx}, a class to make simple booklets with
  \LaTeXe}]{\textbf{\thepage}}
\rhead[\textbf{\thepage}]{\textbf{\upshape The file
    \texttt{booklet.dtx}, a class to make simple booklets with
    \LaTeXe}} \cfoot{}
%    \end{macrocode}
%    \begin{macrocode}
\EnableCrossrefs   % Make a full index.
%\DisableCrossrefs % Make no index.
\CodelineIndex     % Index by line numbers rather than by page.
%\PageIndex        % index commands using page numbers.
\DoNotIndex{\textbf,\texttt,bfseries,\renewcommand,\providescommand}
\DoNotIndex{\filedate,\filename,\fileversion}
\DoNotIndex{\DoNotIndex,\arabic}
\DoNotIndex{\NeedsTeXFormat}
\RecordChanges     % Show change history.
%\OnlyDescription  % uncomment this to not format the code.
\title{The file \texttt{booklet.dtx}, a class to make simple booklets
      with \LaTeXe.\thanks{This file has version number \fileversion,
      dated \filedate.}\\[2pt]
      It contains the code for \texttt{booklet.cls}}
\author{Nick Urbanik}
\date{\filedate}
\begin{document}
\thispagestyle{empty}
\maketitle
\providecommand{\Lenv}[1]{\textsf{#1}}
\providecommand{\pkg}[1]{\texttt{#1}}
\providecommand{\file}[1]{\texttt{#1}}
\DocInput{booklet.dtx}
\PrintIndex
\PrintChanges
%    \end{macrocode}
% Now tell the people what they need to do next to get the index and
% change list:
%    \begin{macrocode}
\typeout{Next, to make the index and changes list for this documentation:}
\typeout{2. makeindx -s gind.ist booklet}
\typeout{3. makeindx -s gglo.ist -o booklet.gls booklet.glo}
\typeout{Finally, run this file through LaTeX once more.}
%    \end{macrocode}
%
%    \begin{macrocode}
\end{document}
%</driver>
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Identification part}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    \begin{macrocode}
%<*class>
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{booklet}%
      [1996/01/28 A class to make simple booklets]
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Declaration of options}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% There are no options for this class yet.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  \subsubsection{The \texttt{oddleft} option}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \LaTeX\ classes generally assume that in a document produced with
% the |twoside| option the pages are numbered with odd-mumbered pages
% on the right.  This is okay for books, but for booklets sometimes it
% makes sense to have a cover, then pages numbered from 1 onwards,
% with page 1 on the left.  Unfortunately, |varioref| still will not
% cope with this, but this option makes other things work okay.
%
%    \begin{macrocode}
\DeclareOption{oddleft}%
{%
   \AtEndOfClass%
   {%
% Now here I've changed the page setup to be similar to that for my
% assembly language primer, except that the left and right margins are
% exchanged, since here the odd-numbered pages are on the left, while
% in a book, the odd-numebred pages are on the right.
%
% This is what the documentation for the \pkg{vmargin} package has to say:
% \begin{quote}
% Two sided printing is supported, meaning that if on odd pages the left
% margin is, say, 30\,mm and the right margin is 20\,mm, it will be vice
% versa on even pages. This gives equal margins on the outer and the
% inner edge of the paper, as expected e.g. for a book.
% \end{quote}
% Here we are making an A5 booklet, obtained by folding A4 paper in half:
%    \begin{macrocode}
\setpapersize{A5}%
\setmarginsrb{20mm}% left For a book, the inner.  For oddleft, outer.
             {9mm}% top
             {13mm}% right For a book, the outer.  For oddleft, inner.
             {10mm}% bottom
             {12pt}% headheight---increase to stop fancyhead warn
             {4mm}%  headsep
             {0pt}%  footheight
             {8mm}% footskip
%    \end{macrocode}
% Later note: it seems that the 8mm footskip is not a problem with the new
% footers; still, will check after examining the output.
% \begin{verbatim}
%            {13mm}% footskip
% \end{verbatim}
% \begin{macro}{\headwidth}
%    \begin{macrocode}
\renewcommand{\headwidth}{\textwidth}%
%    \end{macrocode}
% \end{macro}
%
% All changes to |\textwidth| to happen before here (I can't remember
% whether this commandment comes from the documentation for
% \pkg{fancyheadings} or elsewhere).
%
% News flash!  It seems that it is critical to put this before
% redefining the |\sectionmark| and |\subsectionmark|, otherwise the
% new definitions are ignored!
%    \begin{macrocode}
\pagestyle{fancyplain}
%    \end{macrocode}
% Hey: this seems to work!  A simple adaptation from my assembly
% language primer page setup.  Note that it is \emph{essential} to put
% the |\pagestyle| first, otherwise these are ignored!
%    \begin{macrocode}
\renewcommand*{\sectionmark}[1]%
    {\markboth{\thesection\ \  #1}{\thesection\ \  #1}}
\renewcommand*{\subsectionmark}[1]{\markright{\thesubsection\ \ #1}}
%    \end{macrocode}
%
% This is the format of the |\lhead| and |\rhead| commands,
% for reference.
% \begin{verbatim}
% \lhead[\fancyplain{plain LH-even}{normal LH-even}]
%       {\fancyplain{plain LH-odd }{normal LH-odd}}
% \rhead[\fancyplain{plain RH-even}{normal RH-even}]%
%       {\fancyplain{plain RH-odd }{normal RH-odd}}
% \end{verbatim}
% We want the subsection number on the right hand page: that's an even
% number in this arrangement.
%    \begin{macrocode}
\lhead[%
         \fancyplain{}%
         {%
            \bfseries\rightmark%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
            \rmfamily\bfseries \thepage%
         }%
      }
%    \end{macrocode}
%    \begin{macrocode}
\rhead[%
         \fancyplain{}%
         {%
            \rmfamily\bfseries \thepage%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
            \bfseries\leftmark%
         }%
      }%
%    \end{macrocode}
% We want the subsection number on the right hand page: that's an even
% number in this arrangement.
%    \begin{macrocode}
\lfoot[%
         \fancyplain{}%
         {%
         }%
      ]%
      {%
         \fancyplain{\tiny\revision}%
         {%
               \tiny\revision%
         }%
      }
%    \end{macrocode}
% We want the section number on the left hand page: that's an
% odd-numbered page in this arrangement.
%    \begin{macrocode}
\rfoot[%
         \fancyplain{}%
         {%
            \tiny\revision%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
         }%
      }
   }%
   \typeout{^^JUsing the leftopen option^^J}
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Allow other classes to be base classes}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This stuff was stolen from |exam.dtx|.  Note that |cweb.cls|
% implements this in a better way.  Unfortunately, I do not understand
% how that works from the quick look I had.  To do later.
% \begin{macro}{\BookletBaseClass}
%    \begin{macrocode}
\providecommand{\BookletBaseClass}{article}
%    \end{macrocode}
% \end{macro}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Pass all other options unchanged to \texttt{\BookletBaseClass.cls}}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    \begin{macrocode}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\BookletBaseClass}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Execution of options}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SHOULD WE USE |\ExecuteOption{..}| instrad or as well as this?
% If see |classes.dtx|. |\ExecuteOptions| provides defaults that can
% be overridden.
%
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Special class file commands}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Do we pass the default options here?  Or in |\PassOptionsToClass|?
%    \begin{macrocode}
\LoadClass[a5paper,twoside]{\BookletBaseClass}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Package loading}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    \begin{macrocode}
\RequirePackage{%
   vmargin,%
   fancyheadings,%
   %array,%
   nick,%
   varioref,%
   %ifthen,%
   %verbatim,%
   rcs,%
   %slidesec,%
   %fancybox,%
   %version,%
   %alltt%
}
%    \end{macrocode}
%    \begin{macrocode}
%\PassOptionsToClass{twoside}{\BookletBaseClass}
%    \end{macrocode}
% Now here I've changed the page setup to be similar to that for my
% assembly language primer, except that the left and right margins are
% exchanged, since here the odd-numbered pages are on the left, while
% in a book, the odd-numebred pages are on the right.
%
% This is what the documentation for the \pkg{vmargin} package has to say:
% \begin{quote}
% Two sided printing is supported, meaning that if on odd pages the left
% margin is, say, 30\,mm and the right margin is 20\,mm, it will be vice
% versa on even pages. This gives equal margins on the outer and the
% inner edge of the paper, as expected e.g. for a book.
% \end{quote}
% Here we are making an A5 booklet, obtained by folding A4 paper in half:
%    \begin{macrocode}
\setpapersize{A5}%
\setmarginsrb{13mm}% left For a book, the inner.  For oddleft, outer.
             {9mm}% top
             {20mm}% right For a book, the outer.  For oddleft, inner.
             {10mm}% bottom
             {12pt}% headheight---increase to stop fancyhead warn
             {4mm}%  headsep
             {0pt}%  footheight
             {8mm}% footskip
%    \end{macrocode}
% Later note: it seems that the 8mm footskip is not a problem with the new
% footers; still, will check after examining the output.
% \begin{verbatim}
%            {13mm}% footskip
% \end{verbatim}
% \begin{macro}{\headwidth}
%    \begin{macrocode}
\renewcommand{\headwidth}{\textwidth}%
%    \end{macrocode}
% \end{macro}
%
% \paragraph{Revision control}
%
% This uses the \textsf{RCS} \textbf{r}evision \textbf{c}ontrol
% \textbf{s}ystem and the macros \cmd{\RCS$Revision: 1.2 $} and \cmd{\RCS$Date: 1996/03/04 12:15:30 $} to
% create a footer on the left page of the booklet.  The macros must be
% defined in the source file for the booklet.  Using \textsf{RCS}
% seems the simplest way to automate tracking document revisions.
% \begin{macro}{\revision}
%    \begin{macrocode}
\newcommand{\revision}{ver \RCSRevision{}%
                        ,\hspace{0.8ex} \RCSDate%
                      }
%    \end{macrocode}
% \end{macro}
% All changes to |\textwidth| to happen before here (I can't remember
% whether this commandment comes from the documentation for
% \pkg{fancyheadings} or elsewhere).
%
% News flash!  It seems that it is critical to put this before
% redefining the |\sectionmark| and |\subsectionmark|, otherwise the
% new definitions are ignored!
%    \begin{macrocode}
\pagestyle{fancyplain}
%    \end{macrocode}
% Hey: this seems to work!  A simple adaptation from my assembly
% language primer page setup.  Note that it is \emph{essential} to put
% the |\pagestyle| first, otherwise these are ignored!
%    \begin{macrocode}
\renewcommand*{\sectionmark}[1]%
    {\markboth{\thesection\ \  #1}{\thesection\ \  #1}}
\renewcommand*{\subsectionmark}[1]{\markright{\thesubsection\ \ #1}}
%    \end{macrocode}
%
% This is the format of the |\lhead| and |\rhead| commands,
% for reference.
% \begin{verbatim}
% \lhead[\fancyplain{plain LH-even}{normal LH-even}]
%       {\fancyplain{plain LH-odd }{normal LH-odd}}
% \rhead[\fancyplain{plain RH-even}{normal RH-even}]%
%       {\fancyplain{plain RH-odd }{normal RH-odd}}
% \end{verbatim}
% We want the subsection number on the right hand page: that's an even
% number in this arrangement.
%    \begin{macrocode}
\lhead[%
         \fancyplain{}%
         {%
            \rmfamily\bfseries \thepage%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
            \bfseries\rightmark%
         }%
      }
%    \end{macrocode}
%    \begin{macrocode}
\rhead[%
         \fancyplain{}%
         {%
            \bfseries\leftmark%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
            \rmfamily\bfseries \thepage%
         }%
      }%
%    \end{macrocode}
% We want the subsection number on the right hand page: that's an even
% number in this arrangement.
%    \begin{macrocode}
\lfoot[%
         \fancyplain{}%
         {%
               \tiny\revision%
         }%
      ]%
      {%
         \fancyplain{\tiny\revision}%
         {%
         }%
      }
%    \end{macrocode}
% We want the section number on the left hand page: that's an
% odd-numbered page in this arrangement.
%    \begin{macrocode}
\rfoot[%
         \fancyplain{}%
         {%
         }%
      ]%
      {%
         \fancyplain{}%
         {%
            \tiny\revision%
         }%
      }
%    \end{macrocode}
%    \begin{macrocode}
\cfoot{}
%    \end{macrocode}
%    \begin{macrocode}
\typeout{^^JMaking a BOOKLET^^J}
%</class>
%    \end{macrocode}
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
%% \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         \~}
%%
% \Finale
