% \iffalse -*- LaTeX -*-
%
%   This is file `cjw-latex.dtx'.  You can run this file through
%   LaTeX2e to produce a DVI file of documentation.  The file
%   `cjw-latex.ins' should have come with this file.  Run it through
%   (La)TeX to extract the bundled macro files.
%
% \fi
\def\RCSinfo{$Id: cjw-latex.dtx,v 0.13 1998/09/01 15:54:20 cwynne Exp $}

\def\RCSsplit $#1: #2,v #3 #4 #5 #6 #7${
  \gdef\filename   {#2}
  \gdef\fileversion{#3}
  \gdef\filedate   {#4}
  \gdef\filetime   {#5}
  \gdef\fileauthor {#6}
  \gdef\filelocker {#7}}

\expandafter\RCSsplit\RCSinfo
%%
%% \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         \~}
%%
%  \CheckSum{0}
%
% \iffalse
%<*driver>

\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{cjw-latex.dtx}
    [\filedate\space v\fileversion\space
     Personal macros for LaTeX2e---CJW]

\documentclass{ltxdoc}
  \usepackage{cjwmacro}
    % We need math---call it with all options to make sure they work.
  \usepackage[derivs,integrals,physics]{cjwmath}

\GetFileInfo{cjw-ltr.dtx}
\EnableCrossrefs         
% \DisableCrossrefs     % Say \DisableCrossrefs if index is ready
% \OnlyDescription      % Comment out for implementation details
\RecordChanges

\begin{document}
  \DocInput{cjw-latex.dtx}
\end{document}
%</driver>
% \fi
%
% \DeclareRobustCommand{\cseq}[1]{\texttt{\bslash#1}}
% \DeclareRobustCommand{\pkg} [1]{\textsf{#1}}
% \DeclareRobustCommand{\env} [1]{\textsf{#1}}
%
% \renewcommand{\thefootnote}{\fnsymbol{footnote}}
%
% \title{The \pkg{cjw-latex} Macro Collection\thanks{%
%   This file has version \fileversion{} as of \filedate.}}
% \author{Colin J.~Wynne\thanks{E-Mail at:
%   \texttt{cwynne@mts.jhu.edu}, \texttt{cwynne@jhu.edu}\,.}}
% \date{\filedate}
%
% \maketitle
%
% \setcounter{StandardModuleDepth}{1}
%
% {\parskip 0pt         ^^A % This is the hack used by |doc.dtx|.
%                       ^^A % (bug in \LaTeX?)
%  \tableofcontents
% }
%
% \section*{Introduction}
%
% I have been a \TeX{} user for quite a long time now.  It was in my
% junior year in college, in 1992, that one of my friends and one of
% my math professors decided to warp my perception of reality and
% introduce me to Dr.~Knuth's wonderful creation.  In those days,
% Plain-\TeX{} was the tool of choice, we coded everything ourselves
% from primitives on up, logical markup was unknown, and \LaTeX{} was
% known as Lame-\TeX.  During my senior year I wrote an honors thesis
% in mathematics which required quite a lot of things not present in
% standard Plain-\TeX.  My macro files grew, and grew, and\dots
%
% In the year following my graduation, I converted myself to \LaTeX{},
% mostly because of the convergence my own personal modified
% ePlain/NFSS1/Plain format was having towards \LaTeX{} in terms of
% logical markup.  Most of macros were easily converted into
% \LaTeX{}-ese.  They got more complicated from there.
%
% So now I regularly write up papers, letters, mathematical problem
% sets, and just about anything else that uses the English language,
% in \LaTeX.  The macros have evolved quite a bit.  More has been
% added.  I took to using the |dtx| format for most of my input files,
% and finally decided to wrap my big three up into a single documented
% source file.
%
% I hope that these macros will prove useful to somebody out there,
% and if they do, feel free to buy me a beer next time you see me.  I
% have other |dtx| files available, including a modified \pkg{letter}
% class which also does German formal letters, and a package for doing
% outlines.  Any package of mine should be identifiable on your
% friendly neighborhood CTAN site with a name like
% \verb+cjw*.(dtx|ins)+.
%
% \section{General macros}
%
% \iffalse
%
\NeedsTeXFormat{LaTeX2e}
%<general>\ProvidesPackage{cjwmacro}
%<math>\ProvidesPackage{cjwmath}
%<deriv>\ProvidesFile{cjwderiv.tex}
%<integ>\ProvidesFile{cjwinteg.tex}
%<phys>\ProvidesFile{cjwphys.tex}
%<units>\ProvidesFile{cjwunits}
    [\filedate\space v\fileversion\space
%<general>     Personal macros for LaTeX2e---CJW]
%<math>     Math macros for LaTeX2e---CJW]
%<deriv>     Derivative macros for cjwmath.sty---CJW]
%<integ>     Integration macros for cjwmath.sty---CJW]
%<phys>     Physics macros for cjwmath.sty---CJW]
%<units>     Typesetting units in LaTeX2e---CJW]
%
%<*general>
%
%\fi
%
% I tend to organize my package files as follows---first come flow
% control structures for the package itself, usually in the form of
% new conditionals; then come the options; then comes the meat of the
% package in some sort of vaguely thought out order.  This package is
% no exception.  
%
% \subsection{Package initialization}
%
% Conditionals are usually used in conjunction with package options to
% provide conditional inclusion of certain code, either \emph{via} an
% \cseq{if}\dots{}\cseq{endif} block or using class options.  For this
% package, the subsystem in question is the inclusion of verbatim
% typeset files.
%    \begin{macrocode}
\newif\if@verbext       \@verbextfalse
%    \end{macrocode}
% Not surprisingly, this conditional is used directly by an option.
%    \begin{macrocode}
\DeclareOption{verbext}{\@verbexttrue}
%    \end{macrocode}
% I used to use options for the loading of additional packages.  In
% particular, when I used \pkg{psfig.new} which could not be handled
% as a \LaTeXe{} package, I did this.  Now that I use the \pkg{epsfig}
% package that comes with \LaTeXe, I simply issue a warning to
% include the package separately.
%    \begin{macrocode}
\DeclareOption{psfig}{%
  \PackageWarning{cjwmacro}%
    {Obsolete option \CurrentOption.  Use package `epsfig' instead.}}
%    \end{macrocode}
% Since, however, using \pkg{pstricks} requires several files, I still
% use a package option to take care of all of that.  This option
% checks for the existence of \emph{both} files before including
% either, hence the nested calls to \cseq{InputIfFileExists}.  A
% similar option is used for \pkg{pst-plot.tex}, since is not
% implemented as a package file.
%    \begin{macrocode}
\DeclareOption{pstricks}{%
  \InputIfFileExists{pstricks.sty}{%
  \InputIfFileExists{pst-node.tex}{}{%
    \PackageError{cjwmacro}{File `pst-node.sty' not found.}{}}}%
   {\PackageError{cjwmacro}{File `pstricks.sty' not found.}{}}}

\DeclareOption{psplot}{\InputIfFileExists{pst-plot.tex}{}{%
  \PackageError{cjwmacro}{File `pst-plot.tex' not found.}{}}}
%    \end{macrocode}
%
% The next two options are used to change behavior of some macros on
% draft as opposed to final copies.  Currently, only \cseq{ssbreak}
% has such a dependency, and in final form it uses the PS-Tricks
% package to typeset a nice section delimiter.  Note the use of
% \cseq{ExecuteOption} by the \pkg{final} option to make sure that
% PS-Tricks is, indeed, available.
%    \begin{macrocode}
% What to do for draft vs. final copy.
\DeclareOption{draft}{%  
  \def\ssbreakbar{\hbox to 2in{\hrulefill}}}
\DeclareOption{final}{%
  \ExecuteOptions{pstricks}  
  \def\ssbreakbar{%
    \psset{linewidth=0.4pt,unit=1in}%
    \pspicture(-2.5,-0.15)(2.5,0.15)%
      \qdisk(0,0){0.04}%
      \qdisk(0.33,0){0.02}%
      \qdisk(-0.33,0){0.02}%
      \pspolygon*(0.33,-0.02)(0.33,0.02)(1.75,0)%
      \pspolygon*(-0.33,-0.02)(-0.33,0.02)(-1.75,0)%
    \endpspicture}}
%    \end{macrocode}
%
% To finish off option handling, we declare a default (warn about
% unknown options), execute defaults, and process the passed option
% list. 
%    \begin{macrocode}
\DeclareOption*{%
  \PackageWarning{cjwmacro}{Unknown option `\CurrentOption'}}
\ExecuteOptions{draft}
\ProcessOptions
%    \end{macrocode}
%
% \subsection{General definitions}
%
% These general definitions set up some `meta-macros', to be used by
% other commands.
%
% One of the things I liked a lot about \TeX{} was the use of
% \cseq{let} to make aliases for existing commands without
% sacrificing much of the control sequence space.  In the spirit of
% \LaTeXe, however, I have implemented this thrice with name
% checking.  Analogously to the \cseq{newcommand}-like macros, we
% offer the following three:
%    \begin{macrocode}
\newcommand{\alias}       [2]{\@ifdefinable #1{\let #1 #2}}
\alias\realias\let
\newcommand{\providealias}[2]{\@ifundefined #1{\let #1 #2}}
%    \end{macrocode}
% Usage is, for example,
%   \begin{display}{l}
% \cseq{alias}\cseq{foo}\cseq{bar}
%   \end{display}
% which makes \cseq{foo} an alias for \cseq{bar}.  As expected,
% \cseq{alias} only works if the new name is currently undefined and
% \cseq{providealias} does nothing if its first argument is already
% defined.  Somewhat more lax than its counterpart
% \cseq{renewcommand}, \cseq{realias} does not care if its first
% argument is defined or not.  In essence, that command is used to
% unconditionally alias a command.  This is why, oddly enough,
% \cseq{realias} is itself just an alias of \cseq{let}.  Is this
% getting confusing yet?
%
% Next we input wholesale a few useful packages.  These are still in
% the spirit of meta-macros which define this section.  The first
% package, \pkg{amstext}, provides the \cseq{text} command, which
% basically puts its argument in text mode inside a box, but in the
% current style (textstyle, scriptstyle, etc.).  This is used later
% on.  The \pkg{xspace} package is used for control sequences which
% would encounter `the space problem' when expanded as is.
%    \begin{macrocode}
\RequirePackage{amstext}
\RequirePackage{xspace}
%    \end{macrocode}
% The command \cseq{intertext} from the \pkg{amsmath} package is quite
% useful, but I do not want to include that entire package unless it
% is necessary.  Therefore, I make sure that command is defined one
% way or another.  I also give it the alias \cseq{rem} since I am
% somewhat nostalgic about ancient forms of \textsf{\small BASIC}\dots{}
%    \begin{macrocode}
\providecommand{\intertext}[1]{\noalign{%
  \penalty\postdisplaypenalty\addvspace{ 0.5\belowdisplayskip}
  \vbox{\normalbaselines\noindent#1}%
  \penalty\predisplaypenalty\addvspace{0.5\abovedisplayskip}}}
\alias\rem\intertext
%    \end{macrocode}
%
% Next we define some font style names which will be used in some
% contexts later.  This is done to avoid hard-coding of certain styles
% and to allow as much customization as possible.
%    \begin{macrocode}
\providecommand{\pagenofont}    {\normalfont}
\providecommand{\declarefont}   {\normalfont\bfseries\mathversion{bold}}
\providecommand{\altdeclarefont}{\normalfont\itshape}
\providecommand{\captionfont}   {\normalfont\itshape}
\providecommand{\examplefont}   {\normalfont}
\providecommand{\altexamplefont}{\normalfont\itshape}
\providecommand{\labelfont}     {\normalfont\bfseries\mathversion{bold}}
\providecommand{\timelinefont}  {\normalfont}
\providecommand{\titlefont}     {\normalfont\bfseries\Large\mathversion{bold}}
\providecommand{\verbatimfont}  {\normalfont\ttfamily}
%    \end{macrocode}
%
% The next few commands are for programming convenience.  First we
% want to be able to swap the definitions of two control sequences.
%    \begin{macrocode}
\newcommand{\swapdef}[2]{{%
         \let \@tempa #1\relax
  \global\let #1      #2\relax
  \global\let #2      \@tempa}}
%    \end{macrocode}
% We also want to be able to do the same for lengths (or glue or
% whathaveyou).
%    \begin{macrocode}
\newcommand{\swapdim}[2]{{%
         \@tempdima #1\relax
  \global #1        #2\relax
  \global #2        \@tempdima}}
%    \end{macrocode}
% Next is a macro constructed from an exercise in \emph{The
% \TeX{}book}, which takes three control sequences and expands them in
% reverse order.
%    \begin{macrocode}
\newcommand{\expandthree}[2]{%
  \expandafter\expandafter\expandafter #1\expandafter #2}
%    \end{macrocode}
%
% This next macro is modified from code I received in the
% |comp.text.tex| newsgroup.  According to the e-mail in which I
% received it, the original source is a set of macros for
% \emph{TUGboat}.  It turns a number into an ordinal, finding the
% correct ordinal label which is set as a superscript.
%    \begin{macrocode}
\newcommand{\nth}[1]{{%
  \@tempcnta = #1\relax
  \ifnum \@tempcnta < 0\relax           % Make sure our number is
    \@tempcnta = -\@tempcnta            %   non-negative.
  \fi
  \ifnum \@tempcnta < 14\relax          % Deal first with the 
    \ifnum \@tempcnta > 10\relax        %   exceptions for 
      \def\@tempa{th}                   %   11, 12, and 13.
    \fi
  \else
    \loop \ifnum\@tempcnta > 9\relax    % Loop until the recursive
      \@tempcntb = \@tempcnta           %   remainder (mod 10) is
      \divide  \@tempcntb by  10\relax  %   a single digit in order
      \multiply\@tempcntb by  10\relax  %   to successfully satisfy
      \advance \@tempcnta by -\@tempcntb%   the ordinality test.
    \repeat
    \def\@tempa{\ifcase\@tempcnta       % Figure the proper label:
              th%                       %   0th
        \or   st%                       %   1st
        \or   nd%                       %   2nd
        \or   rd%                       %   3rd
        \else th%                       %   nth
      \fi}
  \fi
  #1\ensuremath{^{\text{\@tempa}}}}}    % Superscript the label in
                                        %   math mode.
%    \end{macrocode}
%
% Continuing in the vein of superscripts, we define two macros which
% put their arguments as sub- and superscripts in script-script
% style.  This was motivated by such things as derivative indices
% which look just plain ugly in script style.
%    \begin{macrocode}
\alias\sst\scriptscriptstyle
\newcommand{\ssp}[1]{^{\sst#1}}
\newcommand{\ssb}[1]{_{\sst#1}}
%    \end{macrocode}
%
% We now come to some very important and necessary macros, namely the
% creation of typeset sideways \textsf{\small ASCII} smiley
% faces. \smiley  Since I like to be as general as possible, I have
% also written  an \cseq{emote} macro for indicating
% emotions. \emote{smirk} 
%    \begin{macrocode}
\newcommand{\smiley}[1][\@smiley]{%
  \edef\@sf{\spacefactor=\the\spacefactor}%
  \unskip\spacefactor=1000\relax\space #1\@sf\xspace}
\newcommand{\@smiley}{%
  {\ttfamily\raise 0.078em\hbox{:}\kern-0.1em{-}\kern-0.1em{)}}}
\newcommand{\emote}[1]{%
  \smiley[\ensuremath{\langle}\emph{#1}\ensuremath{\rangle}]}
%    \end{macrocode}
%
% Since I learned the good habit of doing so at Washington and Lee, I
% often append pledges to my assignments.  The generic pledge is
% implemented as an environment.  It formerly took an argument, the
% date, but I decided that was superfluous, seeing as how the
% assignment headers set the date once.  Why risk inconsistency?  Much
% to my surprise, I found out that \LaTeXe's \cseq{maketitle} command
% unsets not only the date holder, but also the command which is used
% to set the date in the first place.  Anyhow, this means that the
% date \emph{does} need to be set, but I have left that to be done by
% the headers.  The \env{pledge} environment issues a warning if the
% date is not set.
%    \begin{macrocode}
\newenvironment{pledge}%
  {\ifx\@empty\@date
      \PackageWarning{cjwmacro}{Date is not set.}
   \fi
   \parskip=2pt \parindent=0pt\relax
   \null\vfill\begin{flushright}
     \itshape\small}
  {\\[5ex]\normalfont\footnotesize
     \makebox[2in]{\hrulefill}\quad\@date\\
     \makebox[2in]{Colin J.~Wynne}\quad{\hphantom{\@date}}\\
   \end{flushright}}
%    \end{macrocode}
% The old Washington and Lee pledge lives on in my macros\dots{}  It
% requires one argument, namely the type of assignment being pledged.
% The argument is optional, though, and a paper is assumed by default.
%    \begin{macrocode}
\newcommand{\wnlpledge}[1][paper]{%
  \ifx\@empty\@date
    \PackageWarning{cjwmacro}{Date is not set.}
  \fi
  \parskip=2pt \parindent=0pt\relax
  \null\vfill\begin{flushright}
    \itshape\small
    On my honour, I have neither given nor received\\
    any unacknowledged aid on this #1.\\[5ex]
    \normalfont\footnotesize
    \makebox[2in]{\hrulefill}\quad\@date\\
    \makebox[2in]{Colin J.~Wynne,~'94}\quad{\hphantom{\@date}}\\
  \end{flushright}}
%    \end{macrocode}
%
% As mentioned in the option section, there is a macro used to put
% fancy section delimiters into, say, a story.  The \cseq{ssbreak}
% command expects the type of delimiter, the \cseq{ssbreakbar}, to be
% defined.  Since either \pkg{draft} or \pkg{final} must be chosen as
% an option, this should be fine, but I have put a hopefully redundant
% command in just in case.
%    \begin{macrocode}
\newcommand{\ssbreak}{\bigskip
  \centerline{\ssbreakbar}\bigbreak}
\providecommand{\ssbreakbar}{}
%    \end{macrocode}
%
% \subsection{Box formatting}
%
% I have written some of my own commands for handling boxes.  The
% first thing I wanted was an analog of \cseq{mbox} or \cseq{hbox} for
% math mode.  The simple version---\cseq{mathbox} puts its argument into an
% \cseq{hbox}, in math mode, in the current style.  The second version
% is \cseq{Mathbox}, which takes two arguments, the first of which is
% put in the box and evaluated \emph{before} math mode is entered.
% This was done for a specific application where I needed to get the
% contents of the \cseq{mathbox} itself into boldface.  Of course,
% \cseq{boldmath} cannot be evaluated within math mode.  Note that the
% style is chosen by the \cseq{mathpalette} macro, and that the
% command \cseq{@mathbox} is essentially just a dummy to allow the
% proper expansion of \cseq{mathpalette}.
%    \begin{macrocode}
% \mathbox puts its argument into an \hbox, in math mode, with the
% current \...style.
\def\mathbox #1{\hbox{$\mathpalette\@mathbox{#1}$}}
\def\Mathbox #1#2{\hbox{#1$\mathpalette\@mathbox{#2}$}}
\def\@mathbox#1#2{#1#2}
%    \end{macrocode}
% Now, there is a reason why these are defined with \cseq{def} and not
% \cseq{newcommand}.  You see, what I really wanted to do was
% something like
%   \begin{verbatim}
% \newcommand{\mathbox}[2][]{%
%   \hbox{#1$\mathpalette\@mathbox{#1}$}}
% \newcommand{\@mathbox}[2]{#1#2}
%   \end{verbatim}
% in order to get optional arguments to my \cseq{mathbox}es.  The
% problem, though, is that I want to use this command in the context
% of |\box|$N$|=\mathbox{|\dots{}|}|, and for that to work, the first
% token in the expansion of \cseq{mathbox} \emph{must} be a
% |\|$?$|box| command.  The overhead imposed by \cseq{newcommand}
% precludes this.  So, I use the cheap hack until I figure out a more
% workable way of implementing what I really want.
%
% A more generically applicable box command is one which does unto
% width what \cseq{smash} does to height.  Hence \cseq{smush}:
%    \begin{macrocode}
\newcommand{\smush}{\relax
  \ifmmode
    \def\next{\mathpalette\math@smush}
  \else
    \let\next\make@smush
  \fi \next}
\newcommand{\make@smush}[1]{\setbox0=\hbox{#1}\fin@smush}
\newcommand{\math@smush}[2]{\setbox0=\hbox{$\m@th#1{#2}$}\fin@smush}
\newcommand{\fin@smush}{\wd0=0pt \box0 }
%    \end{macrocode}
%
% And finally, vaguely in the realm of boxes, we have struts.  Here I
% have defined some math struts of various sizes (corresponding to the
% various delimiter sizes on which they are based).
%    \begin{macrocode}
\newcommand{\bigmathstrut} {\vphantom{\big()}}
\newcommand{\biggmathstrut}{\vphantom{\bigg()}}
\newcommand{\Bigmathstrut} {\vphantom{\Big()}}
\newcommand{\Biggmathstrut}{\vphantom{\Bigg()}}
%    \end{macrocode}
%
% \subsection{Abbreviations, etc.}
%
% I have found myself using particular types of abbreviations quite
% often---often enough that I wanted control sequences for them,
% whence these first few specimens.
%    \begin{macrocode}
\newcommand{\ie}    {\emph{i.e.}\xspace}
\newcommand{\eg}    {\emph{e.g.}\xspace}
\newcommand{\heisst}{d.h\null.\xspace}          % \dh is taken.
%    \end{macrocode}
% Note the use of \cseq{xspace} so that explicit space need not be
% given afterward.  I did this mostly because I have never decided
% whether or not I want to use a comma after either of this.
%
% The second type of abbreviation is the initial, or should I say
% initials.  I finally settled on a style I like---two initials should
% be separated by a thinspace, and will of course need to have the
% spacefactor adjusted if at the end of a sentence (followed by a
% period, in particular).  Here is the implementation:
%    \begin{macrocode}
\newcommand{\initials}[2]{%
  \break@init #2
  \@ifdefinable #1{%
    \global\edef#1{%
      \noexpand\hbox{\@tempa.\noexpand\,\@tempb}%
      \noexpand\@ifnextchar.{\noexpand\@}{.\noexpand\xspace}}}}
\def\break@init #1.#2.{%
  \def\@tempa{#1}\def\@tempb{#2}}
%    \end{macrocode}
% What happens is this.  The \cseq{initials} command is given a
% control sequence name and the initials to be used.  The initials are
% broken on the periods and returned in the specified tokens.  Then,
% if the control sequence is available for definition, it is defined
% in such a way to make all the spacing and punctuation work out.
% Since the tokens need to be expanded back to the separate initials,
% an \cseq{edef} is required---at the same time, use of
% \cseq{noexpand} is made to keep things from going kablooie at
% definition time.  Here are some standard initials by way of usage
% example.
%    \begin{macrocode}
\initials{\UN}{U.N.}
\initials{\US}{U.S.}
\initials{\AI}{A.I.}
%    \end{macrocode}
%
% \subsection{Dates}
%
% I have had call to do a fair amount of \TeX{} in both English and
% German.  Therefore, in implementing the examples of date macros from
% \emph{The \TeX{}book}, I have provided for both languages.
%
%    \begin{macrocode}
% LaTeX style commands for date-parts, both English and German.
\providecommand{\theday}{\number\day\relax}
\providecommand{\themonth}{%
  \ifcase\month\or January\or February\or%
  March\or April\or May\or June\or July\or August\or%
  September\or October\or November\or December\fi}
\providecommand{\themonat}{%
  \ifcase\month\or Januar\or Februar\or%
  M\"arz\or April\or Mai\or Juni\or Juli\or August\or%
  September\or Oktober\or November\or Dezember\fi}
\providecommand{\theyear}{\number\year\relax}
%    \end{macrocode}
% Note that \cseq{today} is unconditionally defined by the following
% underhandedness. 
%    \begin{macrocode}
\providecommand{\today}{}
\renewcommand{\today}{\theday~\themonth, \theyear\xspace}
\providecommand{\heute}{}
\renewcommand{\heute}{den~\theday.\ \themonat\ \theyear\xspace}
  \alias\gdate\heute
%    \end{macrocode}
%
% \subsection{Page styles and titles}
%
% We are finally into the realm of more traditional package macros,
% namely creating some general page appearances.  Here I have
% redefined the \pkg{plain} pagestyle to take advantage of the
% \cseq{pagenofont} defined above.
%    \begin{macrocode}
\renewcommand{\ps@plain}{%
  \let\@mkboth  \@gobbletwo
  \let\@oddhead \@empty
  \let\@evenhead\@empty
  \def\@oddfoot{\pagenofont\hfil\thepage\hfil}
  \let\@evenfoot\@oddfoot}
%    \end{macrocode}
% The \pkg{topright} pagestyle has page numbers (strangely enough) at the top
% right of the page.
%    \begin{macrocode}
\newcommand{\ps@topright}{%
  \let\@mkboth  \@gobbletwo
  \def\@oddhead{\pagenofont\hfil\thepage}
  \let\@evenhead\@oddhead
  \let\@oddfoot \@empty
  \let\@evenfoot\@empty}
%    \end{macrocode}
%
% \subsection{Text formatting}
%
% \subsubsection{Timelines}
%
% A timeline is a long, running, two-column format used, for example,
% to do r\'esum\'es or vit\ae (or, if you are in Germany, a
% \emph{Lebenslauf}).  The idea is that a date (or some identifying
% information) appears at the left, and the content is given in the
% righthand column.  The usage is
%   \begin{display}{l}
% |\timeline[|\meta{pos}|]{|\meta{date}|}|
%   \end{display}
% where \meta{pos} is exactly the argument to \cseq{makebox}, the
% justification of the \meta{date} entry within the lefthand column.
% That column has length \cseq{timelineskip}, which can off course be
% set as desired.
%    \begin{macrocode}
\newlength{\timelineskip}
\setlength{\timelineskip}{1.75in}
%    \end{macrocode}
% The actual entries are not considered to be two separate columns.
% Rather, the first line is padded out to \cseq{timelineskip} with
% makebox, and following lines use a hanging indentation.  The control
% sequence \cseq{endtimeline} is defined trivially so that a timeline
% entry may be used as a \env{timeline} environment.
%    \begin{macrocode}
\newcommand{\timeline}[2][l]{%
  \noindent\hangindent=\timelineskip
  \makebox[\timelineskip][#1]{\timelinefont{#2}}\ignorespaces}
\let\endtimeline\relax
%    \end{macrocode}
%
%  \subsubsection{Mathematical declarations}
%
% In writing up mathematics, one often wishes to declare definitions,
% theorems, and so forth.  I have written generic declaration macros
% which can be customized for these uses.  Since I prefer to have all
% such things numbered seuqentially, they use a common counter, called
% \cseq{declare}, strangely enough.  They are numbered within sections
% if sections are being numbered.
%    \begin{macrocode}
\@ifundefined{c@section}
  {\newcounter{declare}}
  {\newcounter{declare}[section]
   \renewcommand{\thedeclare}{\thesection.\arabic{declare}}}
%    \end{macrocode}
% When declarations are numbered, it is sometime nice to have the
% declaration type and number appear uniformly wide throughout.  This
% is done by forcing the declaration to appear in a box of width
% \cseq{declareindent}.
%    \begin{macrocode}
\newlength{\declareindent}
  \setlength{\declareindent}{0pt}
%    \end{macrocode}
% We use some internal commands to specify exactly how the declaration
% is typeset.  In fact, we will be defining not only declaration, but
% an alternate declaration form so that two different methods may be
% used simultaneously in a document---\eg, when theorems and major
% results are to be italicized, but definitions and so forth are not.
%    \begin{macrocode}
\newcommand{\@declare}   [1]{{\declarefont#1:}\quad}
\newcommand{\@altdeclare}[1]{{\altdeclarefont#1:}\quad}
%    \end{macrocode}
% The generic declarations are environments, and are provided in both
% numbered (normal) and unnumbered (starred) forms.  The latter are
% more simple.
%    \begin{macrocode}
\newenvironment{declaration*}[1]%
  {\medbreak\noindent\ignorespaces
     \@declare{#1}\ignorespaces}%
  {\kern0pt\nobreak\smallskip}
\newenvironment{altdeclaration*}[1]%
  {\medbreak\noindent\ignorespaces
     \@altdeclare{#1}\ignorespaces}%
  {\kern0pt\nobreak\smallskip}
%    \end{macrocode}
% The numbered versions introduce nothing surprising, but are a tad
% more involved.
%    \begin{macrocode}
\newenvironment{declaration}[1]%
  {\medbreak\refstepcounter{declare}
     \noindent\ignorespaces
     \ifnum\declareindent = 0\relax%
       \@declare{\thedeclare\quad #1}
     \else
       \makebox[\declareindent]{\@declare{\thedeclare\hss #1}}
     \fi\ignorespaces}
  {\kern0pt\nobreak\smallskip}
\newenvironment{altdeclaration}[1]%
  {\medbreak\noindent\ignorespaces
     \refstepcounter{declare}
     \ifnum\declareindent = 0\relax
       \@altdeclare{\thedeclare\quad #1}
     \else
       \makebox[\declareindent]{\@altdeclare{\thedeclare\hss #1}}
     \fi\ignorespaces}
  {\kern0pt\nobreak\smallskip}
%    \end{macrocode}
% Now, because I am essentially lazy and do not want the extra typing
% needed for an environment, I have shortcuts, \cseq{declare} and
% \cseq{altdeclare}, as well as numbered versions \cseq{ndeclare} and
% \cseq{altndeclare}.  The first argument is passed to the
% corresponding environment, and the following paragraph is the body
% of the environment.
%    \begin{macrocode}
\def\declare    #1#2\par{%
  \begin{declaration*}{#1}#2\end{declaration*}\par}
\def\altdeclare #1#2\par{%
  \begin{altdeclaration*}{#1}#2\end{altdeclaration*}\par}
\def\ndeclare   #1#2\par{%
  \begin{declaration}{#1}#2\end{declaration}\par}
\def\altndeclare#1#2\par{%
  \begin{altdeclaration}{#1}#2\end{altdeclaration}\par}
%    \end{macrocode}
% Genreality is all well and good, but there are some stock
% declarations, given here in both numbered and unnumbered versions.
%    \begin{macrocode}
\providecommand{\corollary}   {\declare{Corollary}}
\providecommand{\definition}  {\declare{Definition}}
\providecommand{\lemma}       {\declare{Lemma}}
\providecommand{\proposition} {\declare{Proposition}}
\providecommand{\theorem}     {\declare{Theorem}}
\providecommand{\note}        {\altdeclare{Note}}

\providecommand{\ncorollary}  {\ndeclare{Corollary}}
\providecommand{\ndefinition} {\ndeclare{Definition}}
\providecommand{\nlemma}      {\ndeclare{Lemma}}
\providecommand{\nproposition}{\ndeclare{Proposition}}
\providecommand{\ntheorem}    {\ndeclare{Theorem}}
\providecommand{\nnote}       {\altndeclare{Note}}
%    \end{macrocode}
% In addition, the following German declaration (meaning a claim) is
% also defined.
%    \begin{macrocode}
\providecommand{\behaupt}	  {\declare{Behauptung}}
\providecommand{\nbehaupt}	  {\ndeclare{Behauptung}}
%    \end{macrocode}
% Finally, since one is not likely to mix numbered and unnumbered,
% here is a control sequence that will make sure everything is
% numbered. 
%    \begin{macrocode}
\newcommand{\allndeclares}{%
  \let\declare     \ndeclare
  \let\altdeclare  \altndeclare}
%    \end{macrocode}
%
% Now that we have propositions, claims, and theorems (oh my!), we
% want to be able to prove them.  The first step is to define a proof
% environment.  The environment simply sets up a label and some
% spacing.  The label is in |\altdeclarefont|.  The label is an
% optional argument which defaults to `Proof', oddly enough.
%    \begin{macrocode}
\newenvironment{proof}[1][Proof]%
  {\smallbreak\noindent{\altdeclarefont#1:}%
     \quad\ignorespaces}%
  {\qed}
%    \end{macrocode}
% Just in case you are prooving in German, we also have the following:
%    \begin{macrocode}
\newenvironment{beweis}[1][Beweis]%
  {\smallbreak\noindent{\altdeclarefont#1:}%
     \quad\ignorespaces}%
  {\qed}
%    \end{macrocode}
% Note that the end of a proof has the command |\qed|, which we will
% unconditionally define here.  This is adapted from \emph{The
% \TeX{}book}.  The idea is to right justify |\qedsymbol| on the line
% where |\qed| is invoked, unless there is not a comfortable amount of
% room.  That amount is given as 2\,em.  When this happens, the line
% is broken and the |\qedsymbol| appears flush right on the following
% line. 
%    \begin{macrocode}
\providecommand{\qed}{}
  \renewcommand{\qed}{%
    {\unskip\nobreak\hfil\penalty 50%
     \hskip 2em\hbox{}\nobreak\hfil\qedsymbol%
     \parfillskip=0pt \finalhyphendemerits=0 \par}}
%    \end{macrocode}
% The standard end-of-proof symbol is a box, but I prefer somewhat
% less ink.  I use \TeX's hollow diamond suit symbol (again
% unconditionally defined).
%    \begin{macrocode}
\providecommand{\qedsymbol}{}
  \renewcommand{\qedsymbol}{\lower 0.35ex\hbox{$\diamondsuit$}}
%    \end{macrocode}
% In case it is desired, the box symbol is defined as |\qedbox|, and
% then with a simple alias this can be used to end all proofs.
%    \begin{macrocode}
  \newcommand{\qedbox}{\vrule height4pt width3pt depth2pt}
%    \end{macrocode}
% Now we wish to define control sequences for some constructions
% commonly found in proofs.  I often find myself writing out proofs
% which require cases.  There are two types of cases.  Often I will
% want to have two cases, one for each definition of an equivalence
% for example.  In this case, the case delimiters will be something
% like |\then| and |\when| commands, and should be set in parentheses
% to mark them clearly.  The other type is the more general `Case
% $n$:' (where $n$, one hopes, will not be \emph{too} large).  To
% cover both of these, we use a fairly typical \LaTeX{} conceit:
%   \begin{display}{l}
% |\Case*{|\meta{case}|}|
%   \end{display}
% where the unstarred argument sets \meta{case} inside parentheses and
% the star supresses the parentheses.  A German alias is given.
%    \begin{macrocode}
\newcommand{\Case}{\@ifstar{\@starCase}{\@Case}}
\newcommand{\@starCase}[1]{\@@Case{#1}}
\newcommand{\@Case}[1]{\@@Case{(#1)}}
\newcommand{\@@Case}[1]{%
  \noindent{\declarefont#1}\quad\ignorespaces}
\alias\Fall\Case
%    \end{macrocode}
% And finally, just in case the proof is by contradiction, we have the
% following.
%    \begin{macrocode}
\newcommand{\contra}{\ensuremath{\Rightarrow\Leftarrow}}
%    \end{macrocode}
%
%
% \subsubsection{Problems and examples}
%
% In addition to declarations, and for subjects other than
% mathematics, one might want to provide examples and worked
% problems.  I implement examples as a separate environment (well,
% \emph{four} separate environments) so that they may have fonts
% distinct from declarations.
%    \begin{macrocode}
\newenvironment{example*}%
  {\@nameuse{declaration*}{Example}\examplefont}
  {\medbreak}
\newenvironment{altexample*}%
  {\@nameuse{declaration*}{Example}\examplefont}
  {\medbreak}
\newenvironment{example}%
  {\declaration{Example}\examplefont}
  {\medbreak}
\newenvironment{altexample}%
  {\declaration{Example}\examplefont}
  {\medbreak}
%    \end{macrocode}
%
% Problems are handled differently.  In my experience, problems do not
% appear in longwinded documents using sectioning, and so the counter
% need not be embedded.
%    \begin{macrocode}
\newcounter{problem}
  \setcounter{problem}{0}
\renewcommand{\theproblem}{\arabic{problem}}
\renewcommand{\p@problem}{}
%    \end{macrocode}
% Often when working a problem, one wishes to include a reference to
% the source.  This is accomplished via the \cseq{Page} macro.  Usage
% is 
%   \begin{display}{l}
% |\Page*[|\meta{author}|]{|\meta{pp}|}{|\meta{problem}|}|
%   \end{display}
% In the \LaTeX{} tradition, the standard command tries to outguess
% you by prepending a hash `\#' to the problem number, whereas the
% starred version omits this.  Thus, the standard version produces
%   \begin{display}{l}
% ([\meta{author},~]p.\,\meta{pp}, \#\meta{problem})
%   \end{display}
% and \cseq{Page*} leaves off the hash.  Notice that the space between
% author and page number is inserted by the macro.  The macro is
% defined robustly so that it can be used in moving arguments.
%    \begin{macrocode}
\DeclareRobustCommand{\Page}{%
  \@ifstar{\@Page{}}{\@Page{\#}}}
\def\@Page#1{%
  \@ifnextchar [{\@@Page{#1}}{\@@Page{#1}[]}}
\def\@@Page#1[#2]#3#4{%
  \def\@tempa{#2}%
  \ifx\@empty\@tempa%
    \let\@tempb\@tempa%
  \else%
    \edef\@tempb{\@tempa,~}%
  \fi%
  (\@tempb p.\,#3, #1{#4})}
%    \end{macrocode}
% 
% The statement of a problem is given in an environment, again so that
% font customization can be easily done.  The \env{statement}
% environment takes a single optional argument, which is typeset at
% the beginning of the statement in \cseq{altdeclarefont}.  The rest
% of the statement is in \cseq{declarefont}.  I use the optional
% argument to pass a \cseq{Page} reference most often---note, though,
% that if the optional argument to \cseq{Page} is used, the whole
% \cseq{Page} command should be put in braces sp that the square
% brackets of optional arguments do not get confused.
%    \begin{macrocode}
\newenvironment{statement}[1][\null]%
  {\def\@tempa{#1}\def\@tempb{\null}%
    \ifx\@tempa\@tempb%
      \def\@tempc{\null}%
    \else%
      \def\@tempc{\altdeclarefont\@tempa\quad}%
    \fi%
    \declarefont{\@tempc}\ignorespaces}
  {\removelastskip\nopagebreak\smallskip}
%    \end{macrocode}
% A problem, now, is basically just a wrapper for the statement.  It
% generates and sets the problem number, does some spacing, and the
% body of the \env{problem} environment becomes the body of the
% \env{statement}.  In essence, a \env{problem} is a numbered
% \env{statement}.   There is a starred version which does not do
% numbers and references---this just does the correct spacing and
% calls \env{statement}. Note that the problem number is set using a
% macro from the \pkg{cjw-outl} package.
%    \begin{macrocode}
\newenvironment{problem}%
  {\setcounter{equation}{0}%
    \gdef\theequation{\theproblem.\arabic{equation}}%
    \removelastskip\medbreak%
    \refstepcounter{problem}%
    \noindent\theoutlabel{\theproblem.}%
    \statement}
  {\endstatement}
\newenvironment{problem*}%
  {\removelastskip\medbreak%
   \noindent\statement}
  {\endstatement}
%    \end{macrocode}
% Since I have been known to write assignments in German, we provide
% the aliases to make an \env{aufgabe} environment.
%    \begin{macrocode}
\alias  \aufgabe   \problem
\realias\endaufgabe\endproblem
%    \end{macrocode}
% For parts and subparts of problems, the aliases are English and the
% main definitions are German because I wrote these while I was in
% Germany.  So, parts (\emph{Teile}) are numbered within problems and
% subparts (\emph{Subteile}) within parts.  The defaults for
% cross-referencing (the \cseq{p@} forms) are set, too.
%    \begin{macrocode}
\newcounter{teil} [problem]
\newcounter{steil}[teil]
\renewcommand{\theteil}  {(\alph{teil})}
  \renewcommand{\p@teil} {\theproblem}
\renewcommand{\thesteil} {(\roman{steil})}
  \renewcommand{\p@steil}{\p@teil\theteil}
%    \end{macrocode}
% The environment \env{part}/\env{teil} used to be implemented
% entirely in terms of the \pkg{cjw-outl} package, but that was a
% little bit of overkill, and made the numbering more difficult to
% implement.  I ought to one day implement problems/parts/subparts
% entirely in terms of the outline macros.  We'll see.
%
% Anyway, the current implementations still rely on some of the
% definitions from the \pkg{cjw-outl} package.  The
% \env{part}/\env{teil} environments take a single optional argument,
% namely the outline depth.  Level one starts the text flush left at
% the margin, which is usually where the \env{problem} is, hence a
% \env{part} should be at level two, and this is the default.  A more
% detailed explanation of the goings-on here can be found in
% \pkg{cjw-outl.dtx}. 
%    \begin{macrocode}
\newenvironment{teil}[1][2]%
  {\@tempcnta=#1\advance\@tempcnta by -1\relax
   \ifnum\@tempcnta < 1\relax
     \leftskip=0pt\relax
   \else
     \leftskip=\@tempcnta\outlindent
   \fi
   \refstepcounter{teil}
   \addvspace{\medskipamount}%
   \noindent\theoutlabel{\theteil}%
   \ignorespaces}
  {\par\smallbreak}
%    \end{macrocode}
% The default level for \env{ppart} or \env{steil}, the subpart
% environments, is three.
%    \begin{macrocode}
\newenvironment{steil}[1][3]%
  {\@tempcnta=#1\advance\@tempcnta by -1\relax
   \ifnum\@tempcnta < 1\relax
     \leftskip=0pt\relax
   \else
     \leftskip=\@tempcnta\outlindent
   \fi
   \refstepcounter{steil}
   \addvspace{\medskipamount}%
   \noindent\theoutlabel{\thesteil}%
   \ignorespaces}
  {\par\smallbreak}
%    \end{macrocode}
% English aliases are, of course, given.
%    \begin{macrocode}
\realias\part    \teil
\realias\endpart \endteil
\alias  \ppart   \steil
\realias\endppart\endsteil
%    \end{macrocode}
%
% \subsubsection{Footnotes}
%
% This is a simple modification to a standard \LaTeXe{} internal
% macro, because I prefer hanging indentation on my footnote text.
%    \begin{macrocode}
\long\def\@makefntext#1{%
  \parindent 1em\noindent\hangindent=\parindent%
  \hb@xt@    1em{\hss \llap{\@makefnmark} }#1}
%    \end{macrocode}
%
% \subsubsection{Text displays}
%
% I have turned the \cseq{begindisplay} and \cseq{enddisplay} macro
% pair from \emph{The \TeX{}book} (page~421) into a \LaTeX{}
% environment.  As with Knuth's macros, local definitions for use
% within the display can be given, in this case via the
% \env{display}'s optional argument.  Since the environment is
% implemented through the standard \env{tabular} environment, there is
% a mandatory argument specifying column layout.  Overall, usage is
%   \begin{display}{l}
% \cseq{begin}|{display}[|\meta{local}|]{|\meta{cols}|}|
%   \end{display}
% with local definitions \meta{local} and column descriptol
% \meta{col}.  (By the way, the previous display was created with the
% \env{display} environment\dots)
%
% The display's offset from the left margin is specified by
% \cseq{textdisplay indent}.  Default value is equal to
% \cseq{parindent}, and is therefore set below, after
% \cseq{parindent}. 
%    \begin{macrocode}
\newlength{\textdisplayindent}
%    \end{macrocode}
% The actual \env{display} environment uses the spacing and penalties
% of mathematical displays.
%    \begin{macrocode}
\newenvironment{display}[2][]
  {\vadjust{\penalty\predisplaypenalty}
   \@newline[\abovedisplayskip]%
   \begingroup%
     #1%
     \begin{tabular}{@{\null\hspace{\textdisplayindent}\null}#2}}
  {\end{tabular}\endgroup
   \vadjust{\penalty\postdisplaypenalty}
   \@newline[\belowdisplayskip]\ignorespaces}
%    \end{macrocode}
%
% \subsection{Verbatim inclusions}
%
% Since I only occassionally need to include verbatim files, the
% following macros need to be specifically included by a package
% option, as was mentioned above.
%    \begin{macrocode}
\if@verbext
%    \end{macrocode}
% For numbered inclusions, we need a line number counter.
%    \begin{macrocode}
\newcounter{vfline}
\renewcommand{\thevfline}{\arabic{vfline}}
%    \end{macrocode}
% We need the following command from \emph{The \TeX{}book}.
%    \begin{macrocode}
\providecommand{\uncatcodespecials}{%
  \def\do##1{\catcode`##1=12 }\dospecials}
%    \end{macrocode}
% The basic command is \cseq{verbfile} which takes an optional
% argument specifying the starting line number (default is one), and a
% mandatory argument which is, of course, the name of the file to
% include.  There is also \cseq{verbfilenolines} which does not number
% lines, and needs only the one mandatory argument.
%    \begin{macrocode}
\providecommand{\verbfile}[2][1]{%
  \par\begingroup\@vf@lines{#1}\input{#2}\relax\endgroup}
\providecommand{\verbfilenolines}[1]{%
  \par\begingroup\@vf@nolines\input{#1}\relax\endgroup}
%    \end{macrocode}
% In the manner of command which need to do \cseq{catcode} trickery,
% the above are primarily wrappers for the real commands.  The one
% problem with these as currently implemented is that they do not
% handle leading space in the included file.  Oh, well.
%    \begin{macrocode}
\newcommand{\@vf@lines}[1]{%
  \verbatimfont
  \setcounter{vfline}{#1}
    \addtocounter{vfline}{-1}
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{0pt}
  \def\par{\leavevmode\endgraf}
  \obeylines \uncatcodespecials \obeyspaces
  \everypar{\null\stepcounter{vfline}%
    \llap{\scriptsize\thevfline\quad}\null}}
\newcommand{\@vf@nolines}{%
  \verbatimfont
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{0pt}
  \def\par{\leavevmode\endgraf}
  \obeylines \uncatcodespecials \obeyspaces
  \everypar{\null}}
%    \end{macrocode}
% Now we end the inclusion conditional.
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
% \subsection{Initialization}
%
% We use the \cseq{AtBeginDocument} command to set up some default
% values when the document is actually started.
%    \begin{macrocode}
\AtBeginDocument{%
  \setlength{\parindent}        {20pt}
  \setlength{\parskip}          { 2pt plus 1pt}
  \setlength{\textdisplayindent}{\parindent}}
%    \end{macrocode}
%
% \iffalse
%
%</general>
%
% \fi
%
%
% \section{Math macros}
%
% \iffalse
%
%<*math>
%
% \fi
%
% While some macros useful for typesetting mathematics have already
% been covered, none of them had to do with mathematical equations or
% symbols---they were macros for logical flow and delineation.  In
% this package, \pkg{cjwmath}, I have written macros which are
% specifically for typesetting the actual math---the vast majority of
% these macros, if not actually all of them, are meant to be used in
% math mode.
%
% \subsection{Package initialization}
%
% Since different papers require different types of math, I have again
% used the introduction of conditionals and package options to control
% what code is actually loaded.  The important one concerns use of the
% AMS math packages in AMS-\LaTeX.  This is included as an option to
% my package because some of my definitions depend upon whether the
% AMS macros are being used.  There are conditionals for including
% code for calculus (both derivatives and integrals) and some code for
% physics.
%    \begin{macrocode}
\newif \if@amsmath
\newif \if@derivatives
\newif \if@integrals
\newif \if@physics
%    \end{macrocode}
% There are options corresponding to each conditional.
%    \begin{macrocode}
\DeclareOption{amsmath}  {\@amsmathtrue}
\DeclareOption{derivs}   {\@derivativestrue}
\DeclareOption{integrals}{\@integralstrue}
\DeclareOption{physics}  {\@physicstrue}
%    \end{macrocode}
% There used to be another option for typesetting units.  While I
% originally included that code in this package directly, I found
% several occasions where I wanted units but not the rest of the math
% code.  Therefore, units are in a separate package, and the option
% now just reminds the user to input that package by itself.
%    \begin{macrocode}
\DeclareOption{units}{%
  \PackageWarning{cjwmath}%
    {Obsolete option \CurrentOption.  Use package `cjwunits' instead.}}
%    \end{macrocode}
% Finally, there is a default option, to warn about unknown options,
% and the passed option list is processed.
%    \begin{macrocode}
\DeclareOption*{%
  \PackageWarning{cjwmath}{Unknown option `\CurrentOption'}}
\ProcessOptions
%    \end{macrocode}
%
% This package depends upon the previous one.
%    \begin{macrocode}
\RequirePackage{cjwmacro}
%    \end{macrocode}
% It also uses the AMS fonts, for which we require \pkg{amssymb},
% which itself requires \pkg{amsfonts}.
%    \begin{macrocode}
\RequirePackage{amssymb}
%    \end{macrocode}
% Just in case things get screwy in \pkg{cjwmacro}---which they
% shouldn't, we explicitly require \pkg{amstext} here, too, for the
% \cseq{text} command.
%    \begin{macrocode}
\RequirePackage{amstext}
%    \end{macrocode}
% I much prefer the following package to AMS's own blackboard bold
% font. 
%    \begin{macrocode}
\RequirePackage{bbm}
%    \end{macrocode}
% If the \pkg{amsmath} option is specified, we load the package (which
% itself brings in a lot of other stuff).
%    \begin{macrocode}
\if@amsmath
  \RequirePackage{amsmath}
\fi
%    \end{macrocode}
%
% \subsection{Miscellaneous macros}
%
% Here is a package command which I have written to cover the
% shortcomings of AMS-\LaTeX's |\DeclareNewMathOperator| command.  In
% particular, I would like to be able to set different fonts for some
% operators.   The syntax is
%   \begin{display}{l}
% |\NewMathOp*[|\meta{font}|]{\cs}{|\meta{text}|}|
%   \end{display}
% The optional star makes an operator with limits.  The \meta{font}
% is, by default, |\operator@font|.  |\cs| is the name of the new
% mathop.  \meta{text} should be the printed version of the operator,
% but may also include, for example, extra kerning information, as in
%   \begin{display}{l}
% |\NewMathOp[\mathfrak]{\so}{o\kern 0pt}|
%   \end{display}
% The command should produce something robust.
%    \begin{macrocode}
\DeclareRobustCommand{\NewMathOp}{%
  \@ifstar{\@makenewop{\displaylimits}}
          {\@makenewop{\nolimits}}}
%    \end{macrocode}
% The first iteration applies a font if the optional argument is not
% given.
%    \begin{macrocode}
\def\@makenewop#1{%
  \@ifnextchar [{\@@makenewop{#1}}
    {\@@makenewop{#1}[\operator@font]}}
%    \end{macrocode}
% Finally, the net operator itself is declared robustly.  The
% arguments are, in order, either |\displaylimits| or |\nolimits|, the
% font, the control sequence, and the operator text.
%    \begin{macrocode}
\def\@@makenewop#1[#2]#3#4{%
  \DeclareRobustCommand{#3}{%
    \mathop{\kern\z@{#2{#4}}}#1}}
%    \end{macrocode}
%
% The next few macros have to do with things not specific to any
% particular flavor of mathematics.  For example, I like some of the
% alternate Greek characters more than the originals---notice how we
% cleverly required the \pkg{cjwmacro} package which gives us the
% \cseq{swapdef} command.
%    \begin{macrocode}
\swapdef{\epsilon}{\varepsilon}
% \swapdef{\theta}{\vartheta}
\swapdef{\rho}{\varrho}
%    \end{macrocode}
% I also like the empty set symbol from AMS, to which I also assign a
% German alias.
%    \begin{macrocode}
\swapdef{\nothing}{\varnothing}
\alias\leer\nothing
%    \end{macrocode}
%  The standard symbols `$\exists$' and `$\forall$' do not have
% satisfactory spacing, in my opinion, so I redefine them as
% relations.  Notice the aliasing so that the symbols' redefinition
% can be carried out regardless of current math fonts.
%    \begin{macrocode}
\alias\@@exists\exists
  \renewcommand{\exists}{\mathrel{\@@exists}}
\alias\@@forall\forall
  \renewcommand{\forall}{\mathrel{\@@forall}}
%    \end{macrocode}
% What \LaTeX{} cleverly calls \cseq{ni} (a backwards `$\in$') really
% ought to mean `such that,' hence I rename it:
%    \begin{macrocode}
\newcommand{\st}{\mathrel{\ni}}
%    \end{macrocode}
% Being essentially lazy, I also prefer to make a nice control
% sequence for some standard abbreviations.  One happens to be
% German (since in German it is more acceptable to use abbreviations
% of long phrases even in a more formal setting).
%    \begin{macrocode}
\newcommand{\WLOG}{Without loss of generality\xspace}
\newcommand{\Wlog}{without loss of generality\xspace}
\newcommand{\obda}{o.B.d.A.\xspace}
\newcommand{\fp}{floating-point\xspace}
%    \end{macrocode}
% The following two commands are simply for phantoms I often find
% myself using, for example to make alignments in arrays and matrices
% come out right.  The mnemonic is `phantom negative' or `phantom equals'.
%    \begin{macrocode}
\newcommand{\pneg}{\phantom{-}}
\newcommand{\peq}{\phantom{=}}
%    \end{macrocode}
% Going probably too far into the realm of generalization, here are
% some macros to set their arguments inside matching scaled delimiters
% of various sorts.
%    \begin{macrocode}
\newcommand{\anglebrackets}[1]{%
  \left\langle #1 \right\rangle}
\newcommand{\curlybrackets}[1]{%
  \left\{ #1 \right\}}
\newcommand{\squarebrackets}[1]{%
  \left[ #1 \right]}
\newcommand{\vertbrackets}[1]{%
  \left| #1 \right|}
\newcommand{\Vertbrackets}[1]{%
  \left\| #1 \right\|}
%    \end{macrocode}
% And now for something completely different---sometimes an operand
% should be left generic, but not in terms of a variable.  The usual
% way of accomplishing this is to place a small dot where the argument
% would otherwise go.  As I consider this to imply `no argument', the
% command is |\noarg|.
%    \begin{macrocode}
\newcommand{\noarg}{\,\cdot\,}
%    \end{macrocode}
% We end with a few things that should be fairly obvious.
%    \begin{macrocode}
\newcommand{\ee}[1]{\times10^{#1}}
\newcommand{\half}{\sfrac12}
\newcommand{\ninfty}{-\infty}
%    \end{macrocode}
% This is shorthand for function definitions, including an extra
% control sequence for some backwards compatibility and an alias to
% German.
%    \begin{macrocode}
\newcommand{\fcn}[2]{\colon{#1}\rightarrow{#2}}
  \newcommand{\mapping}[3]{{#1}\fkt{#2}{#3}}
\alias\fkt\fcn
%    \end{macrocode}
% Restrictions of functions:
%    \begin{macrocode}
\newcommand{\restr}[2][\big]{\kern -.1em #1|_{#2}}
%    \end{macrocode}
%
%
% \subsection{Combinatorics}
%
% The binomial coefficient $\choose{n}{k}$ is defined, depending on
% whether or not AMS-\LaTeX{} is being used.
%    \begin{macrocode}
\if@amsmath
  \realias\choose\binom
\else
  \renewcommand{\choose}[2]{{{#1}\atopwithdelims(){#2}}}
\fi
%    \end{macrocode}
% And lastly, we have the combinatorial doohickie which is read as
% `$n$ multichoose $k$', using doubled parentheses as delimiters.  I
% think this comes out looking right.
%    \begin{macrocode}
\newcommand{\mchoose}[2]{%
  \mathchoice%
   {\left(\kern-0.48em\choose{#1}{#2}\kern-0.48em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
  }
%    \end{macrocode}
% There is also the old-fashioned $\Comb{n}{k}$-type notation, as used
% both in English and in German.
%    \begin{macrocode}
\newcommand{\Comb}[2]{%                         %   C
  {}_{#1}{\operator@font C}_{#2}}               % #1 #2
\newcommand{\Komb}[2]{%                         %          #2
  {\operator@font Ko}_{#1}^{#2}}                %        Ko
\newcommand{\Kombun}[2]{\Komb{#1,\neq}{#2}}     %          #1
\newcommand{\Perm}[2]{%                         %                #2
  {\operator@font Pe}_{#1}^{#2}}                %              Pe
\newcommand{\Permun}[2]{\Perm{#1,\neq}{#2}}     %                #1
%    \end{macrocode}
%
% \subsection{Sets}
%
% The most important macro in this section is named, of course,
% |\set|.  The idea is to make sets which look like
%   \begin{displaymath}
% \set{x \in \R^2}{\norm{x}_p = 1 \forall p = 1,2,3,\ldots}.
%   \end{displaymath}
% That is, there should be scaled braces around two halves separated
% by a scaled logical delimiter, the vertical bar.  The problem with
% this is getting everything the same height, since the $\mid$
% specifier does not scale and there is no middle-counterpart to
% |\left|\dots|\right|.
%
% So, the command has the form:
%   \begin{display}{l}
% |\set[|\meta{mid}|]{|\meta{left}|}{|\meta{right}|}|
%   \end{display}
% The optional \meta{mid} specifies an alternate delimiter to use
% between the two definition halves of the set.  If it is left
% \emph{empty}, the null delimiter `.' will be assumed.  If anything
% at all appears in the optional argument, though, the first token
% \emph{must} be a delimiter, as it will immediately be preceded by a
% sizing macro.  For example, if you wish to use a colon to separate
% the definitions, use `|[.:]|' as the optional argument.  The
% mandatory \meta{left} and \meta{right} are simply the halves of the
% set definition.
%    \begin{macrocode}
\newcommand{\set}[3][|]{{%
  \newdimen\@tempdimd%
%    \end{macrocode}
% Each half is set in its own box, then the larger of the respective
% heights and depths are determined.
%    \begin{macrocode}
  \setbox0=\mathbox{#2}\@tempdima=\ht0 \@tempdimb=\dp0%
  \setbox0=\mathbox{#3}\@tempdimc=\ht0 \@tempdimd=\dp0%
  \ifdim\@tempdimc > \@tempdima
    \@tempdima=\@tempdimc
  \fi
  \ifdim\@tempdimd > \@tempdimb
    \@tempdimb=\@tempdimb
  \fi
%    \end{macrocode}
% We create an invisible rule with that height and depth, and make
% sure we have a valid delimiter if the optional argument is empty.
%    \begin{macrocode}
  \def\@tempa{\vrule width0pt height\@tempdima depth\@tempdimb}
  \def\@tempb{#1}
  \ifx\@empty\@tempb
    \def\@tempb{.}
  \fi
%    \end{macrocode}
% Finally, we use a null left delimiter to balance the middle
% delimiter, and then a left brace to balance the right brace.  The
% rule is set inside both pairs so that they scale identically.  Note
% the use of |\expandafter| so that when the first |\right| is
% expanded, it can grab the delimiter in |\@tempb|.
%    \begin{macrocode}
  \left.\left\{ \@tempa{#2} \,\expandafter\right\@tempb\,{#3} \right\} }}
%    \end{macrocode}
% For backwards compatibility, I make two aliases for |\set|; the old
% commands required the user to specify the larger side of the set
% definition in order to get sizing correct.
%    \begin{macrocode}
\alias\setl\set
\alias\setr\set
%    \end{macrocode}
%
% Here are some macros for typesetting sets symbolically.  First off,
% we might want to know how to typeset a level set.
%    \begin{macrocode}
\newcommand{\lvl}[2][\alpha]{\Gamma\ssb{#2}\ssp{(#1)}}
%    \end{macrocode}
% There are also fuzzy sets, and their corresponding level sets.
%    \begin{macrocode}
\if@amsmath
  \newcommand{\fset}[1]{\Tilde{#1}}
\else
    \newcommand{\fset}[1]{\tilde{#1}}
\fi
\newcommand{\flvl}[2][\alpha]{\lvl[#1]{\fset{#2}}}
%    \end{macrocode}
% For want of a better font, I will typeset set collections
% in |\mathcal|.
%    \begin{macrocode}
\alias\coll\mathcal
%    \end{macrocode}
%
% Finally, we deal with some set operators.
% \emph{The \TeX{}book} points out the difference between |\setminus|
% and |\backslash|.  I prefer to think of them as `set
% complementation' and `coset', respectively.
%    \begin{macrocode}
\alias\scomp\setminus
\alias\coset\backslash
%    \end{macrocode}
% The next macro attempts to create a symmetric difference operator.
% I don't like it, but I probably won't do better until I learn to
% make my own \textsf{M{\small ETAFONT}} characters\ldots
%    \begin{macrocode}
\newcommand{\symmdiff}{%
  \mathbin{\text{\footnotesize$\bigtriangleup$}}}
%    \end{macrocode}  
%
%
% \subsection{Sequences and series}
%
% Just a few macros are required for various sequences and series,
% mostly for indexing.  The best explanation is simply an example.
% The code
%   \begin{display}{l}
% |$y \in \seq{x_{ij}}$, where $i\inset{n}$, $j\inrange[0]{m}$|
%   \end{display}
% produces
%   \begin{display}{l}
% $y \in \seq{x_{ij}}$, where $i\inset{n}$, $j\inrange[0]{m}$.
%   \end{display}
% 
%    \begin{macrocode}
\newcommand{\seq}    [1]   {\curlybrackets{#1}}
\newcommand{\inset}  [2][1]{\in\{ #1,\ldots,#2 \}}
\newcommand{\inrange}[2][1]{ = #1,\ldots,#2}
%    \end{macrocode}
% 
%
% \subsection{Calculus}
%
% The calculus macros are relegated to auxiliary files, as I rarely
% need them.  
% 
% \subsubsection{Derivatives}
%
% We load the derivatives in if they are requested.
%    \begin{macrocode}
\if@derivatives
  \InputIfFileExists{cjwderiv.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwderiv.tex' not found.}
    \@@derivativesfalse}
\fi
%    \end{macrocode}
% This loads both simple and partial derivative macros.
%\iffalse
%</math>
%<*deriv>
%\fi
%
% The derivatives are all variations on the basic |\dd| macro, which
% should be fairly self explanatory.
%    \begin{macrocode}
\newcommand{\dd} [2]{\frac{d#1}{d#2}}
\newcommand{\ddt}[1]{\dd{#1}{t}}
\newcommand{\ddu}[1]{\dd{#1}{u}}
\newcommand{\ddv}[1]{\dd{#1}{v}}
\newcommand{\ddx}[1]{\dd{#1}{x}}
\newcommand{\ddy}[1]{\dd{#1}{y}}

\newcommand{\sdd} [2]{\frac{d^2#1}{d#2^2}}
\newcommand{\sddx}[1]{\sdd{#1}{x}}
\newcommand{\sddy}[1]{\sdd{#1}{y}}
\newcommand{\sddt}[1]{\sdd{#1}{t}}
\newcommand{\sddu}[1]{\sdd{#1}{u}}
\newcommand{\sddv}[1]{\sdd{#1}{v}}
%    \end{macrocode}
%
% \subsubsection{Partial derivatives}
%
% The partial derivatives are all variations on the theme of |\pard|,
% which is as |\dd|, replacing the $d$ with $\partial$.
%    \begin{macrocode}
\newcommand{\pard} [2]{\frac{\partial#1}{\partial#2}}
\newcommand{\pardx}[1]{\pard{#1}{x}}
\newcommand{\pardy}[1]{\pard{#1}{y}}
\newcommand{\pardz}[1]{\pard{#1}{z}}
\newcommand{\pardu}[1]{\pard{#1}{u}}
\newcommand{\pardv}[1]{\pard{#1}{v}}
\newcommand{\pardt}[1]{\pard{#1}{t}}

\newcommand{\spard} [2]{\frac{\partial^2#1}{\partial#2^2}}
\newcommand{\spardx}[1]{\spard{#1}{x}}
\newcommand{\spardy}[1]{\spard{#1}{y}}
\newcommand{\spardz}[1]{\spard{#1}{z}}
\newcommand{\spardu}[1]{\spard{#1}{u}}
\newcommand{\spardv}[1]{\spard{#1}{v}}
\newcommand{\spardt}[1]{\spard{#1}{t}}

\newcommand{\spardxy}[1]{\frac{\partial^2#1}{\partial x\partial y}}
\newcommand{\spardyx}[1]{\frac{\partial^2#1}{\partial y\partial x}}
\newcommand{\spardxz}[1]{\frac{\partial^2#1}{\partial x\partial z}}
\newcommand{\spardzx}[1]{\frac{\partial^2#1}{\partial z\partial x}}
\newcommand{\spardyz}[1]{\frac{\partial^2#1}{\partial y\partial z}}
\newcommand{\spardzy}[1]{\frac{\partial^2#1}{\partial z\partial y}}
%    \end{macrocode}
%\iffalse
%</deriv>
%<*math>
%\fi
%
% \subsubsection{Integrals}
%
% We load the integrals in if they are requested.
%    \begin{macrocode}
\if@integrals
  \InputIfFileExists{cjwinteg.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwinteg.tex' not found.}
    \@@integralsfalse}
\fi
%    \end{macrocode}
%\iffalse
%</math>
%<*integ>
%\fi
%
% The first macro is simply a variation of |\int| using the |\limits|
% macro. 
%    \begin{macrocode}
\def\integ{\mathop{\int}\limits}
%    \end{macrocode}
% Next we have a small shortcut for the differential at the end of an
% integral.  We work around \LaTeX's font encoding macro.
%    \begin{macrocode}
\alias\latex@d\d
  \renewcommand{\d}{\,d}
%    \end{macrocode}
% We have macros for double and triple integrals, with and without
% |\limits|.
%    \begin{macrocode}
\newcommand{\dint}{\int\!\!\!\int}
\newcommand{\dinteg}{\mathop{\int\!\!\!\int}\limits}
\newcommand{\tint}{\int\!\!\!\int\!\!\!\int}
\newcommand{\tinteg}{\mathop{\int\!\!\!\int\!\!\!\int}\limits}
%    \end{macrocode}
% To be honest, I have no idea why I wrote this one.  It is probably
% buried in a homework file of mine somewhere, but I'll be a fiddler
% crab if I can remember where\dots
%    \begin{macrocode}
\newcommand{\flushintlim}[1]{{\phantom{#1} #1}}
%    \end{macrocode}
%\iffalse
%</integ>
%<*math>
%\fi
%
% \subsection{Algebra}
%
% We define how to typeset an algebra.
%    \begin{macrocode}
\alias\alg\mathbbm
%    \end{macrocode}
%
% \subsubsection{Fields}
%
% A field will also be done in blackboard bold.
%    \begin{macrocode}
\alias\field\mathbbm
%    \end{macrocode}
% The following fields are defined.
%    \begin{macrocode}
\newcommand{\C}{\field{C}}      % Complex
\newcommand{\E}{\field{E}}      % Euclidean (also Evens)
%    \end{macrocode}
% Note that $\H$ is a \LaTeX{} accent, so we save it away before
% redefining it as a field.
%    \begin{macrocode}
\alias\latex@H\H                % Quaternions
  \renewcommand{\H}{\field{H}}	%   (Hamiltonian field)
\newcommand{\N}{\field{N}}	% Natural numbers
\newcommand{\Q}{\field{Q}}	% Rationals
\newcommand{\R}{\field{R}}	% Reals
% \newcommand{\Rn}[1][n]{\R^{#1}}
\newcommand{\Z}{\field{Z}}	% Integers
\newcommand{\pr}{\field{P}}	% Primes
%    \end{macrocode}
%
% \subsubsection{Groups}
%
% Remember |\NewMathOp|?  One use for it is in defining mathematical
% groups.  Here are a bunch.
%    \begin{macrocode}
% Groups are typeset as operators.
\NewMathOp           {\Aut}{Aut}	% Automorphisms
\NewMathOp           {\End}{End}	% Endomorphisms
\NewMathOp           {\GL}{GL}		% General Linear
\NewMathOp           {\Inn}{Inn}	% Inner products
\NewMathOp           {\Pin}{Pin}	% Pin
\NewMathOp           {\SL}{SL}		% Special Linear
\NewMathOp           {\SO}{SO}		% Special Orthogonal
\NewMathOp           {\SU}{SU}		% Special Unitary
\NewMathOp[\mathfrak]{\Sn}{S}		% Symmetric
\NewMathOp           {\Spin}{Spin}	% Spin
\NewMathOp           {\Sp}{Sp}		% Symplectic
\NewMathOp           {\Unit}{U\kern 0pt}% Unitary
\NewMathOp           {\Orth}{O\kern 0pt}% Orthogonal
\NewMathOp[\mathfrak]{\slin}{sl}        % Tangent group to SL
\NewMathOp[\mathfrak]{\so}{o\kern 0pt}  % skew orthogonal
\NewMathOp[\mathfrak]{\sp}{sp}          % skew symplectic
\NewMathOp[\mathfrak]{\su}{u\kern 0pt}  % skew hermitian
%    \end{macrocode}
%
% \subsubsection{Linear algebra}
%
% If matrices are to be typeset specially, we will use the |\mathcal| font.
%    \begin{macrocode}
\alias\mtx\mathcal
%    \end{macrocode}
% I have often seen the letter $\Theta$ used for the matrix of zeros.
% I like it that way.
%    \begin{macrocode}
\newcommand{\nullmtx}{\mtx\Theta}
%    \end{macrocode}
% Taken from Horn and Johnson, a matrix norm can be represented with a
% triple-bar delimiter.
%    \begin{macrocode}
\newcommand{\mnorm}[1]{%
  \left\vert\kern-0.9pt\left\vert\kern-0.9pt\left\vert #1
    \right\vert\kern-0.9pt\right\vert\kern-0.9pt\right\vert}
%    \end{macrocode}
% We define the Lie product of two matrices.
%    \begin{macrocode}
\newcommand{\lie}[1]{\squarebrackets{#1}}
%    \end{macrocode}
% There is an for the trace (Spur, auf Deutsch) of a matrix\dots
%    \begin{macrocode}
\NewMathOp{\Spur}{Spur}
\NewMathOp{\Tr}{Tr}
%    \end{macrocode}
% \dots as well as for diagonal matrices.
%    \begin{macrocode}
\NewMathOp{\Diag}{Diag}
%    \end{macrocode}
%
% This is a shortcut for putting delimiters around matrices.  With
% AMS-\LaTeX, we use an environment, taking as its two mandatory
% arguments the left and right delimiters, respectively.
%    \begin{macrocode}
\if@amsmath
  \newenvironment{arbmatrix}[2]%
    {\def\@tempa{#2}\left#1 \matrix}{\endmatrix \right\@tempa}
%    \end{macrocode}
% Without AMS, we use a command as does standard \LaTeX, and define
% some basic types.
%    \begin{macrocode}
\else
  \newcommand{\arbmatrix}[3]{\left#1 \matrix{#2} \right#3}
  \providecommand{\bmatrix}[1]{\arbmatrix[{#1}]}
  \providecommand{\vmatrix}[1]{\arbmatrix|{#1}|}
\fi
%    \end{macrocode}
%
% The next bit of code is used to enter sparse matrices which are
% often represented in the literature with an oversized zero marking
% the region of zeros.  This takes more than a bit of trickery in
% \LaTeX.  The oversized digit will be put in a box, which in most
% cases needs horizontal and/or vertical adjustment from the position
% where it is placed in the matrix by default.  The default vertical
% offset will be called |\numoffset|, and is set by default to the
% height of a |\Bigmathstrut|.
%    \begin{macrocode}
\newlength{\numoffset}
{\setbox0=\hbox{$\Bigmathstrut$}
 \@tempdima=0.8\ht0\relax
 \global\numoffset\@tempdima}
%    \end{macrocode}
% Occasionally, one might wish to use something other than a zero as
% the oversized digit.  We define a generic |\Number| macro to be
% used.  The usage is
%   \begin{display}{l}
% |\Number|\oarg{raise}\marg{num}
%   \end{display}
% where \meta{raise} is the amount by which the number is raised and
% \meta{num} is the number to be used.
%    \begin{macrocode}
\newcommand{\Number}[2][-\numoffset]{%
  \@tempdima=#1\relax
  \smash{\hbox{\raise\@tempdima\@bignumber{#2}}}}
%    \end{macrocode}
% The macros |\@bignumber| is called to do the dirty work of
% typesetting the number.
%    \begin{macrocode}
\newcommand{\@bignumber}[1]{\hbox{\LARGE$#1$}}
%    \end{macrocode}
% Now, the horizontal adjustment mentioned earlier usually refers to
% the need to have the large digit straddle two columns in a matrix.
% This is easily accomplished with |\multicolumn|.  Here things start
% to get ugly, though; |\multicolumn| must be the first thing after
% the |&| in the array.  But the reasonable way to include an optional
% argument to be passed through to |\Number| is to use the
% |\newcommand| feature, which ends up putting junk in the way---this
% is exactly the same problem which arose in writing |\mathbox|
% earlier.  Therefore, there are currently two separate commands, one
% which takes the optional argument, and one which doesn't.  I would
% really like to remedy this if I ever figure out how.
%    \begin{macrocode}
\def\bignumber    #1{\multicolumn{2}{c}{\Number{#1}}}
\def\Bignumber[#1]#2{\multicolumn{2}{c}{\Number[#1]{#2}}}
%    \end{macrocode}
% Here are some specific cases for using zero, as is most commonly the
% case.
%    \begin{macrocode}
\newcommand{\Zero}[1][-\numoffset]{\Number[#1]{0}}
\def\bigzero    {\bignumber{0}}
\def\Bigzero[#1]{\Bignumber[#1]{0}}
%    \end{macrocode}
% 
% From this we wish to construct various types of matrices.  Each
% variation will have two versions, depending on whether or not
% AMS-\LaTeX{} has been invoked.  Each version, though, has an
% optional argument which is what will be passed through as
% \meta{raise} to |\Bigzero|.  The names of each matrix are an attempt
% to indicate the layout.  For example, the command |\iidiagi| takes
% three mandatory arguments which will be the diagonal entries, the
% first two in the upper left, and the third in the lower right with
% |\ddots| separating them.  Likewise, we have |\idiagii| and
% |\idiagi|. 
%    \begin{macrocode}
\if@amsmath
  \newcommand{\iidiagi}[4][-\numoffset]{%       % 2     0       
    \begin{bmatrix}                             %   3           
       #2 &        &    \Bigzero[#1] \\         %     .         
          &     #3 &        &        \\         %       .       
      \Bigzero[#1] & \ddots &        \\         %   0     4     
          &        &        &    #4                             
    \end{bmatrix}}
  \newcommand{\idiagii}[4][-\numoffset]{%       % 2     0       
    \begin{bmatrix}                             %   .           
       #2 &        & \Bigzero[#1] \\            %     .         
          & \ddots &     &        \\            %       3       
      \Bigzero[#1] &  #3 &        \\            %   0     4     
          &        &     &    #4                                
    \end{bmatrix}}
  \newcommand{\idiagi}[3][-1.2pt]{%             % 2     0
    \begin{bmatrix}                             %   .
       #2 &         \Bigzero[#1] \\             %     .
          & \ddots  &            \\             %       .
      \Bigzero[#1]  &    #3                     %   0     3
    \end{bmatrix}}
\else
  \newcommand{\iidiagi}[4][-\numoffset]{%       % 2     0
    \matrix{%                                   %   3           
       #2 &        &    \Bigzero[#1] \\         %     .         
          &     #3 &        &        \\         %       .        
     \Bigzero[#1] & \ddots &        \\          %   0     4     
          &        &        &    #4}}                           
  \newcommand{\idiagii}[4][-\numoffset]{%                        
    \pmatrix{%                                  % 2     0       
       #2 &        & \Bigzero[#1] \\            %   .           
          & \ddots &     &        \\            %     .         
      \Bigzero[#1] &  #3 &        \\            %       3       
          &        &     &    #4}}              %   0     4
                                  %
  \newcommand{\idiagi}[3][-1.2pt]{%             % 2     0
    \pmatrix{%                                  %   .
       #2 &         \Bigzero[#1] \\             %     .
          & \ddots  &            \\             %       .
      \Bigzero[#1]  &    #3}}                   %   0     3
\fi                                             
%    \end{macrocode}
%
% We now wish to typeset the transpose of a matrix.  The most general
% form is
%   \begin{display}{l}
% |\@trans|\oarg{pre}\marg{post}
%   \end{display}
% which expands to `|^{|\meta{pre}|t|\meta{post}|}|'.  Next is
% |\trans| which takes a single optional argument for \meta{post} (no
% \meta{pre}).
%    \begin{macrocode}
\newcommand{\@trans}[2][]{^{#1\text{\normalfont\textsf{t}}#2}}
\newcommand{\trans} [1][]{\@trans[]{#1}}
%    \end{macrocode}
% Why?  I don't know---I needed |\trinv|, below, and decided to
% generalize.
%    \begin{macrocode}
\newcommand{\trinv}      {\@trans[-]{}}
%    \end{macrocode}
% For backwards compatibility, I have |\ct|\marg{mtx} to represent
% matrix \meta{mtx} as conjugated and transposed.
%    \begin{macrocode}
\newcommand{\ct}[1]{\conj{#1}\trans}
%    \end{macrocode}
%
% The next topic is vectors.  I prefer |\vec| to be logical markup as
% opposed to a specific accent.  Thus, I create an alias |\sarvec|
% (short arrow vector) for the original |\vec|, and another alias
% |\arvec| for a long arrow, which is just |\overrightarrow|.
%    \begin{macrocode}
\alias\sarvec\vec
\alias\arvec \overrightarrow
%    \end{macrocode}
% The actual typesetting I prefer for vectors (when I use anything at
% all) is boldface.  This requires the |\Mathbox| command defined
% earlier so that the argument can be set in a bold math version.
%    \begin{macrocode}
\renewcommand{\vec}[1]{\Mathbox{\boldmath}{#1}}
%    \end{macrocode}
% To typeset vectors in long form simply uses the |\matrix|
% command---but this depends, again, on whether AMS-\LaTeX{} is being
% used.  In either case, a single argument---the contents of the
% vector---is required.  Simply delimit with |\\| for column vectors
% and |&| for rows.
%    \begin{macrocode}
\if@amsmath
  \newcommand{\bvec}[1]{%
    \begin{bmatrix}#1\end{bmatrix}}
  \newcommand{\pvec}[1]{%
    \begin{pmatrix}#1\end{pmatrix}}
%    \end{macrocode}
% There are also two aliases for row vectors for backwards
% compatibility. 
%    \begin{macrocode}
  \alias\brvec\bvec
  \alias\prvec\pvec
\else  
  \newcommand{\bvec}[1]{\bmatrix{#1}}
  \newcommand{\pvec}[1]{\pmatrix{#1}}
% \newcommand{\bvec}[2][r]{%
%   \left[ \begin{array}{#1}#2\end{array} \right]}
% \newcommand{\pvec}[2][r]{%
%   \left( \begin{array}{#1}#2\end{array} \right)}
\fi
%    \end{macrocode}
% The null vector, like the null matrix, is given with $\theta$.
%    \begin{macrocode}
\newcommand{\nullvec}{\vec{0}}
%    \end{macrocode}
% Once we have vectors, we need dot products.  The simple version just
% puts its argument inside angled brackets.
%    \begin{macrocode}
\newcommand{\dotp}[1]{\anglebrackets{#1}}
%    \end{macrocode}
% If special vector notation is required, the two arguments should be
% separated by a comma (which should be the case anyway), and then
% each half is passed to |\vec|.
%    \begin{macrocode}
\newcommand{\vdotp}[1]{\@vdotp#1@@@}
\def\@vdotp #1,#2@@@{\dotp{\vec #1,\vec #2}}
%    \end{macrocode}
% 
% We define some other vector operators to go with the dot product.
% These are the curl, the divergence, and the Laplacian.  These are
% usually read as `del dot', `del cross', and `del squared', so the
% first thing to do is rename the |\nabla|(?).
%    \begin{macrocode}
\newcommand{\del}  {\vec\nabla}
%    \end{macrocode}
% \LaTeX{} defines |\div|, so we rename that and renew the command.
%    \begin{macrocode}
\alias\@@div\div
\renewcommand{\div}{\del\dot}
%    \end{macrocode}
% Finally, we have the other two.
%    \begin{macrocode}
\newcommand{\curl} {\del\cross}
\newcommand{\lapl} {\del^2}
%    \end{macrocode}
%
% In German texts, the linear hull is usually represented as a list of
% vectors in square brackets.
%    \begin{macrocode}
\alias\huelle\squarebrackets
%    \end{macrocode}
% 
% \subsection{Operators}
%
% This section is simply a gathering point for all sorts of
% mathematical operators---not in the |\NewMathOp| sense, like various
% groups defined above, but in the sense of mathematical doohickies
% which take one or two operands and give you something new.
%
% \subsubsection{Binary operators}
%
% What we have first is a whole bunch of names for the large, `x'-like
% times symbol.  In the case of specifying dimension (as in, a 4-by-3
% matrix), we declare it a |\mathord| so as not to invoke binary
% spacing.  Then |\mal| is simply German for `times', and |\cross| is
% the vector space (or group) product using the same symbol.
%    \begin{macrocode}
\newcommand{\by}{\mathord{\times}}
\alias\mal	\times
\alias\cross	\times
%    \end{macrocode}
% To indicate isomorphism, I have most often used an equals sign with
% a tilde above it.
%    \begin{macrocode}
\alias\iso	\simeq
%    \end{macrocode}
% This next one stretches the usefulness of aliasing by defining an
% operator for normal subgroups.
%    \begin{macrocode}
\alias\nsubgrp	\trianglelefteq
%    \end{macrocode}
% Next we specify a congruence symbol.
%    \begin{macrocode}
\realias\cong  	\equiv
%    \end{macrocode}
% In graph theory, we want a symbol for adjacency of nodes.
%    \begin{macrocode}
\alias\adj\leftrightarrow
%    \end{macrocode}
% We unconditionally define |\Box| to be a square operator symbol.
%    \begin{macrocode}
\providecommand{\Box}{}
\renewcommand{\Box}{\mathbin{\square}}
%    \end{macrocode}
% We give a number theoretic division relation, in English and
% German.
%    \begin{macrocode}
\newcommand{\teilt}{\mathbin{|}}
  \alias\divides\teilt
%    \end{macrocode}
% Once upon a time I wanted a `big dot' operator.
%    \begin{macrocode}
% \newcommand{\bdot}{\mathop{\lower0.33ex\hbox{\LARGE$\cdot$}}}
%    \end{macrocode}
% We can use \LaTeX's built-in |\stackrel| to create a definition
% relation. 
%    \begin{macrocode}
\newcommand{\defeq}{\stackrel{\text{def}}{=}}
%    \end{macrocode}
% The symbol I first saw used to indicate disjoint union was a union
% `cup' with a bar through the middle.  Using a naming convention
% similar to AMS-\LaTeX's |\Uplus| we get text and display versions.
%    \begin{macrocode}
\newcommand{\uminus}{%
  \,\,{\mathbin{\cup\kern-.6em{\raise.05em%
  \hbox{-\negthinspace-\kern-.25em-}}}}\,\,}
\newcommand{\Uminus}{%
  \mathop{\bigcup\kern-0.9em{\raise.05em%
  \hbox{-\negthinspace-\kern-.25em-}}}}
%    \end{macrocode}
% We define some handy names for various arrows.
%    \begin{macrocode}
\providecommand{\implies}{\;\Longrightarrow\;}
  \alias\then\implies
\if@amsmath
  \newcommand{\when}{\DOTSB \;\Longleftarrow \;}
\else
  \newcommand{\when}{\;\Longleftarrow \;}
\fi
%    \end{macrocode}
% The following can be used when tracing a series of implications
% through a multiline equation environment, for example.
%    \begin{macrocode}
\newcommand{\limplies}{\llap{$\implies$}\quad}
%    \end{macrocode}
% Based on \emph{The \TeX{}book}, I have written a `skewed' fraction,
% which uses a diagonal separator.
%    \begin{macrocode}
\newcommand{\sfrac}[2]{%
  \hbox{\kern 0.1em%
  \raise 0.5ex\hbox {\scriptsize$#1$}%
  \kern -0.1em $/$%
  \kern -0.15em%
  \lower 0.25ex\hbox {\scriptsize$#2$}}%
  \kern  0.2em}
%    \end{macrocode}
% If we are not using AMS-\LaTeX, the following well not yet be
% defined.
%    \begin{macrocode}
\providecommand{\tfrac}{\sfrac}
\providecommand{\dfrac}[2]{{{#1}\over{#2}}}
%    \end{macrocode}
%
%
% \subsubsection{Unary operators}
%
% I most often use the longer versions of various math accents, so I
% redefine them by default to be long.  The short ones are saved in a
% macro with identical name save for a prepended `s' (as we have
% already seen for |\arvec| and |\sarvec|).  The simple ones are bars,
% tildes, and hats.
%    \begin{macrocode}
\alias\sbar\bar
  \renewcommand{\bar}[1]{\overline{#1}}
\alias\stilde\tilde
  \alias\retilde\widetilde
\alias\shat\hat
  \realias\hat\widehat
%    \end{macrocode}
% We need something better than the default real- and imaginary-part
% macros. 
%    \begin{macrocode}
\renewcommand{\Im}{%
  \mathop{\mathfrak{Im}}}
\renewcommand{\Re}{%
  \mathop{\mathfrak{Re}}}
%    \end{macrocode}
% Complex conjugation is usually denoted by a bar.
%    \begin{macrocode}
\alias\conj  \bar
%    \end{macrocode}
% Inversion of various types is used often enough to warrant a control
% sequence.
%    \begin{macrocode}
\newcommand{\inv}{^{-1}}
%    \end{macrocode}
% To denote power sets, I have used to different alternatives.  The
% default is the standard |\wp| symbol---I don't know what it is
% supposed to be used for, but it can be modified for the task.  On
% the other hand, if we have a real math script font (as one might
% have if using my \pkg{callig} style\dots) we will certainly use
% that. 
%    \begin{macrocode}
\@ifundefined{mathscript}
  {\newcommand{\Pow}{\raise 0.4ex\Mathbox{\Large}{\wp}}}
  {\NewMathOp[\mathscript]{\Pow}{P}}
%    \end{macrocode}
% And what macro would be complete without a German alias?  (Auf
% Deutsch, die Potenzmenge.)
%    \begin{macrocode}
\alias\Pot\Pow
%    \end{macrocode}
% We can leave the letter `\/I\/' to computer scientists who don't
% know how to write an indicator function.  For our purposes, we want
% the neat-o-keen blackboard bold font.
%    \begin{macrocode}
\newcommand{\1}{\mathbbm{1}}
%    \end{macrocode}
%
% Next we have some trigonometric shortcuts.
%    \begin{macrocode}
\alias\acos\arccos
\alias\asin\arcsin
\alias\atan\arctan
%    \end{macrocode}
% Using our generic bracketing macros from earlier, we have absolute
% value, cardinality (order of a set), cyclic generators, and norms.
%    \begin{macrocode}
\alias\abs \vertbrackets
\alias\ord \abs
\alias\cyc \anglebrackets
\alias\norm\Vertbrackets
%    \end{macrocode}
% 
% Multiple sums are recurrent enough (no pun intended \smiley) to get
% macros.  We have double sums, triple sums, and $n$-fold sums.
%    \begin{macrocode}
\newcommand{\dsum}{\mathop{\sum\sum}\limits}
\newcommand{\tsum}{\mathop{\sum\sum\sum}\limits}
\newcommand{\nsum}{\mathop{\sum\sum\cdots\sum}\limits}
%    \end{macrocode}
%
% The next two macros indicate monotone limits, respectively ascending
% (mnemonic `limit up') and descending (you guessed it---`limit
% down').
%    \begin{macrocode}
\NewMathOp*{\ulim}{lim\raise0.4ex\mathbox{\mathord{\smash{\uparrow}}}}
\NewMathOp*{\dlim}{lim\raise0.4ex\mathbox{\mathord{\smash{\downarrow}}}}
%    \end{macrocode}
%
% 
% Finally we have the miscellany, where we can really go to town with
% |\NewMathOp|!  These should be pretty clear, unless you don't do
% math in German, in which case some will be pretty odd.
%    \begin{macrocode}
\NewMathOp*{\argmax}{arg\,max}          % arg min
\NewMathOp*{\argmin}{arg\,min}          % arg min
\NewMathOp {\Aff}   {Aff}               % Affine hull
\NewMathOp {\Bild}  {Bild}              % Bild
\NewMathOp {\Cone}  {Cone}              % Cone
\NewMathOp {\Conv}  {Conv}              % Convex hull
\NewMathOp {\Core}  {Core}              % Fuzzy set core
\NewMathOp {\diam}  {diam}              % diameter
\NewMathOp {\dom}   {dom}               % Domain
\NewMathOp {\Epi}   {Epi}               % Epigraph
\NewMathOp*{\esssup}{ess\,sup}          % Essential supremum
\NewMathOp {\fl}    {fl}                % float-point
\NewMathOp {\ggT}   {ggT}               % ggT
\NewMathOp {\Grad}  {Grad}              % Grad
\NewMathOp {\Hypo}  {Hypo}              % Hypograph
\NewMathOp {\Int}   {Int}               % Interior
\NewMathOp {\Kern}  {Kern}              % Kernel
\NewMathOp {\kgV}   {kgV}               % kgV
\NewMathOp {\Lin}   {Lin}               % Linear hull
\NewMathOp {\lcm}   {lcm}               % LCM
\NewMathOp {\Ord}   {Ord}               % order
\NewMathOp {\proj}  {proj}              % Projection
\NewMathOp {\Rang}  {Rang}              % Rang
\NewMathOp {\range} {range}             % Range
\NewMathOp {\Rank}  {Rank}              % Rank
\NewMathOp {\rot}   {rot}               % Rotation
\NewMathOp {\Span}  {Span}              % Span
\NewMathOp {\val}   {val}               % value
%    \end{macrocode}
% 
% 
% \subsection{Physics}
%
% Now, since physics is a subset of mathematics, physics macros are
% invoked from within the math macro file.
%    \begin{macrocode}
\if@physics
  \InputIfFileExists{cjwphys.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwphys.tex' not found.}
    \@@physicsfalse}
\fi
%    \end{macrocode}
%\iffalse
%</math>
%<*phys>
%\fi
%
% The only thing really specific to physics that I ever used---meaning
% not applicable in any more general mathematical setting---was the
% bra/ket notation.  Here we have bras (br\ae?), kets, and brakets,
% the latter of which bear uncoincidental resemblance to the |\set|
% macro.
%    \begin{macrocode}
\newcommand{\bra}[1]{\left\langle #1 \right|\,}
\newcommand{\ket}[1]{\,\left| #1 \right\rangle}

\newcommand{\braket}[2]{%
  \newdimen\@tempdimd%
  \setbox0=\mathbox{#1}\@tempdima=\ht0 \@tempdimb=\dp0%
  \setbox0=\mathbox{#2}\@tempdimc=\ht0 \@tempdimd=\dp0%
  \ifdim\@tempdimc > \@tempdima
    \@tempdima=\@tempdimc
  \fi
  \ifdim\@tempdimd > \@tempdimb
    \@tempdimb=\@tempdimb
  \fi
  \def\@tempa{\vrule width0pt height\@tempdima depth\@tempdimb}
  \left.\left\langle \@tempa{#1} \,\right|\,{#2} \right\rangle }
%    \end{macrocode}
%\iffalse
%</phys>
%<*math>
%\fi
%
%
% \subsection{Probability}
%
% Here comes that |\NewMathOp| thingie again.  First thing is to
% define some standard probabilistic operators, which really need to
% be typeset in an operator font in order not to look horrible.
%    \begin{macrocode}
\NewMathOp{\Prob} {P}                   % Probability operator
\NewMathOp{\Corr} {Corr}                % Correlation
\NewMathOp{\Cov}  {Cov}                 % Covariance
\NewMathOp{\Expct}{E}                   % Expectation
\NewMathOp{\SD}   {SD}                  % Standard Deviation.
\NewMathOp{\Var}  {Var}                 % Variance
%    \end{macrocode}
% Here is a macro to put inside of some of those operators where
% conditional events are being considered.
%    \begin{macrocode}
\newcommand{\given}{\,|\,}
%    \end{macrocode}
% Usually a single tilde, which as an operator bears the name of
% |\sim| in \LaTeX, indicates a distribution.  Hence, we make an
% alias.
%    \begin{macrocode}
\alias\distrib\sim
%    \end{macrocode}
% And coming back to |\NewMathOp|, we define some standard
% distributions\dots
%    \begin{macrocode}
\NewMathOp{\Bin} {Bin}                  % Binary dist.
  \newcommand{\Nbin}{-\!\Bin}           % Negative Binom.
\NewMathOp{\Exp} {Exp}                  % Exponential dist.
\NewMathOp{\Geom}{Geom}                 % Geometric dist.
\NewMathOp{\Norm}{Norm}                 % Normal dist.
\NewMathOp{\Poi} {Poi}                  % Poisson dist.
\NewMathOp{\Unif}{Unif}                 % Uniform dist.
%    \end{macrocode}
% \dots and the normal density and distribution functions (which might
% also be represented as $\Phi$ and $\phi$).
%    \begin{macrocode}
\NewMathOp[\mathfrak]{\Ndens}{N}
\NewMathOp[\mathfrak]{\Ndist}{n}
%    \end{macrocode}
% The last thing to do is create some macros for probabilistic modes
% of convergence.  We go, again, from the general to the specific.
%    \begin{macrocode}
\NewMathOp*{\@mapsto}{\mapstochar\rightarrow}
\newcommand{\@probconv}[1]{\mathrel{\@mapsto\limits^{1}}}
  \newcommand{\asconv}{\@probconv{a.s.}}        % Almost sure conv.
  \newcommand{\inprob}{\@probconv{P}}           % Conv. in probability
  \newcommand{\inlaw} {\@probconv{L}}           % Conv. in law
  \newcommand{\vague} {\@probconv{v}}           % Vague conv.
%    \end{macrocode}
%
% \iffalse
%
%</math>
%
% \fi
%
%
% \section{Units}
%
% \iffalse
%
%<*units>
%
% \fi
%
% The package \pkg{cjwunits} simply standardizes how to typeset units
% (or dimensions---things such as seconds, meters, and so forth).
% Most of the work is done by defining a pretty simple macro,
% |\unit|.  The rest is just a collection of standard units which may
% be invoked (meaning ones I have used, and therefore stuck into the
% file).
%
% \subsection{Package initialization}
%
% The initialization does most everything.  We first specify a font
% for the unit types.
%    \begin{macrocode}
\newcommand{\unitfont}{\operator@font}
%    \end{macrocode}
% Now the workhorse of the package is defined.  It is pretty
% foolproof, in that it can be invoked in or out of math, may or may
% not be followed by explicit space, and the font as defined above is
% pretty customizable.
%    \begin{macrocode}
\newcommand{\unit}[1]{\ensuremath{\,{\unitfont{#1}\kern\z@}}\xspace}
%    \end{macrocode}
%
% Now come the examples.
%
% \subsection{Distance}
%    \begin{macrocode}
\newcommand{\ang} {\unit{\AA}}                  % angstroms
  \alias\Ao\ang
\newcommand{\cm}  {\unit{cm}}                   % centimetres
\newcommand{\inch}{\unit{in}}                   % inches
\newcommand{\km}  {\unit{km}}                   % kilometres
\newcommand{\mi}  {\unit{mi}}                   % miles
\newcommand{\m}   {\unit{m}}                    % metres
%    \end{macrocode}
%
% \subsection{Electricity and magnetism}
%
%    \begin{macrocode}
\newcommand{\Hz}  {\unit{Hz}}                   % herz
\newcommand{\J}   {\unit{J}}                    % joules
\newcommand{\V}   {\unit{V}}                    % volts
\newcommand{\eV}  {\unit{eV}}                   % electron volts
\newcommand{\erg} {\unit{erg}}                  % ergs
%    \end{macrocode}
%
% \subsection{Mass}
%
%    \begin{macrocode}
\newcommand{\amu} {\unit{amu}}                  % atomic mass units
\newcommand{\gram}{\unit{g}}                    % grams
\newcommand{\kg}  {\unit{kg}}                   % kilograms
\newcommand{\Ton} {\unit{T}}                    % tons
\newcommand{\kT}  {\unit{kT}}                   % kilotons
\newcommand{\MT}  {\unit{MT}}                   % megatons
%    \end{macrocode}
%
% \subsection{Thermodynamics}
%
%    \begin{macrocode}
\newcommand{\kelv}{\unit{K}}                    % kelvins
%    \end{macrocode}
%
% \subsection{Time}
%
% It seems that |\sec| already means secant, so we need a preservation
% and renewal here.
%    \begin{macrocode}
\alias\secant\sec
\renewcommand{\sec} {\unit{s}}                  % seconds
%    \end{macrocode}
%
% \subsection{Velocity}
%
%    \begin{macrocode}
\newcommand{\cee} {\unit{c}}                    % speed o' light
%    \end{macrocode}
%
% \iffalse
%
%</units>
%
% \fi
