%%% ====================================================================
%%%  @LaTeX-file{
%%%     filename        = "amscd.dtx",
%%%     version         = "1.2beta",
%%%     date            = "11-Oct-1994",
%%%     time            = "15:28:49 EDT",
%%%     author          = "American Mathematical Society",
%%%     copyright       = "Copyright (C) 1994 American Mathematical Society,
%%%                        all rights reserved.  Copying of this file is
%%%                        authorized only if either:
%%%                        (1) you make absolutely no changes to your copy,
%%%                        including name; OR
%%%                        (2) if you do make changes, you first rename it
%%%                        to some other name.",
%%%     address         = "American Mathematical Society,
%%%                        Technical Support,
%%%                        Electronic Products and Services,
%%%                        P. O. Box 6248,
%%%                        Providence, RI 02940,
%%%                        USA",
%%%     telephone       = "401-455-4080 or (in the USA and Canada)
%%%                        800-321-4AMS (321-4267)",
%%%     FAX             = "401-331-3842",
%%%     checksum        = "19687 223 739 8716",
%%%     email           = "tech-support@math.ams.org (Internet)",
%%%     codetable       = "ISO/ASCII",
%%%     keywords        = "latex, amslatex, ams-latex, commutative diagram",
%%%     supported       = "yes",
%%%     abstract        = "This file is part of the AMS-\LaTeX{} package.
%%%                        It is a \LaTeX{} option that adapts the commutative
%%%                        diagram macros of AMS-\TeX{} for use in \LaTeX{}",
%%%     docstring       = "The checksum field above contains a CRC-16
%%%                        checksum as the first value, followed by the
%%%                        equivalent of the standard UNIX wc (word
%%%                        count) utility output of lines, words, and
%%%                        characters.  This is produced by Robert
%%%                        Solovay's checksum utility.",
%%%  }
%%% ====================================================================
%\iffalse
%<*driver>
\documentclass{amsdtx}
\usepackage{amscd}
\begin{document}
\title{The \pkg{amscd} package}
\author{Frank Mittelbach\and Rainer Sch\"opf\and Michael Downes}
\date{Version \fileversion, \filedate}
\hDocInput{amscd.dtx}
\end{document}
%</driver>
%\fi
%
% \maketitle
%
% \MakeShortVerb\|
%
% \section{Introduction}
%    The \pkg{amscd} package provides a \env{CD} environment that
%    emulates the commutative diagram capabilities of \amstex/ version
%    2.x (i.e., simple rectangular diagrams, no diagonal arrows or more
%    exotic stuff supported).
%
% \StopEventually{}
%
%    Standard package info.
%    \begin{macrocode}
\ProvidesPackage{amscd}[1994/10/27 v1.2beta]
\RequirePackage{amsgen}
%    \end{macrocode}
%      \verb|\math@cr| shouldn't be defined if it is already defined,
%      because for CD use only we want to omit the part of the code
%      related to \verb|\dspbrk@lvl| (see \fn{amstex.sty}).
%    \begin{macrocode}
\@ifundefined{math@cr}{%
  \def\math@cr{{\ifnum0=`}\fi
    \new@ifstar{\global\@eqpen\@M\math@cr@}%
          {\global\@eqpen\interdisplaylinepenalty \math@cr@}}
}{}
%    \end{macrocode}
%    The following section duplicates some code from the \pkg{amstex}
%    package, in case the \pkg{amscd} package is used by itself. For
%    documentation of the code refer to \fn{amstex.dtx}.
%    \begin{macrocode}
\def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
\def\math@cr@@[#1]{\ifnum0=`{\fi}\math@cr@@@
  \noalign{\vskip#1\relax}}
\def\restore@math@cr{\def\math@cr@@@{\cr}}
\restore@math@cr
\def\rightarrowfill@#1{\m@th\setboxz@h{$#1-$}\ht\z@\z@
  $#1\copy\z@\mkern-6mu\cleaders
  \hbox{$#1\mkern-2mu\box\z@\mkern-2mu$}\hfill
  \mkern-6mu\mathord\rightarrow$}
\def\leftarrowfill@#1{\m@th\setboxz@h{$#1-$}\ht\z@\z@
  $#1\mathord\leftarrow\mkern-6mu\cleaders
  \hbox{$#1\mkern-2mu\copy\z@\mkern-2mu$}\hfill
  \mkern-6mu\box\z@$}
\def\leftrightarrowfill@#1{\m@th\setboxz@h{$#1-$}\ht\z@\z@
  $#1\mathord\leftarrow\mkern-6mu\cleaders
  \hbox{$#1\mkern-2mu\box\z@\mkern-2mu$}\hfill
  \mkern-6mu\mathord\rightarrow$}
\def\atdef@#1{\expandafter\def\csname\space @\string#1\endcsname}
\@ifundefined{Iat}{%
  \DeclareRobustCommand{\Iat}{\FN@\at@}
}{}
\begingroup \catcode`\@=\active
\gdef @{\Iat}
\endgroup
\def\at@{\let\next@\at@@
 \ifcat\noexpand\next a\else
 \ifcat\noexpand\next0\else
 \ifcat\noexpand\next\relax\else
 \let\next@\at@@@\fi\fi\fi\next@}
\def\at@@#1{\expandafter
  \ifx\csname\space @\string#1\endcsname\relax
    \DN@{\at@@@#1}%
  \else
    \DN@{\csname\space @\string#1\endcsname}%
  \fi\next@}%
%    \end{macrocode}
%    The following items should be defined only if they are not
%    already defined, either to leave the package name untouched (in
%    the case of \cs{PackageError}) or to avoid redundant allocation
%    of token or dimen registers.
%    \begin{macrocode}
\@ifundefined{default@tag}{%
  \def\default@tag{%
    \def\tag{\PackageError{amscd}{\protect\tag\space not allowed
      here}\@eha}}%
}{}%
\@ifundefined{at@@@}{%
  \def\at@@@{\PackageError{amscd}{\Invalid@@ @}{\the\athelp@}\char64\relax}
}{}
\@ifundefined{athelp@}{\csname newhelp\endcsname\athelp@
{Only certain combinations beginning with @ make sense to me.^^J%
I'll assume you wanted @@ for a printed @.}}{}
\@ifundefined{minaw@}{\newdimen\minaw@}{}
\@ifundefined{bigaw@}{\newdimen\bigaw@}{}
%    \end{macrocode}
%
%      Assignment of a couple of dimensions, and initialization of
%      \verb=\ampersand@=. We check to see if we need to define
%      \verb=\minaw@= and \verb=\bigaw@=.
%    \begin{macrocode}
\minaw@11.111pt
\newdimen\minCDarrowwidth
\minCDarrowwidth2.5pc
\newif\ifCD@
\let\ampersand@\relax
%    \end{macrocode}
%
%      Added \verb|\restore@math@cr\default@tag| to fix line numbering
%      problems, 7-JUN-1991. Suggested by I.~Zakharevich.
%    \begin{macrocode}
\def\CD{\catcode`\@\active
 \bgroup\relax\iffalse{\fi\let\ampersand@&\iffalse}\fi
 \CD@true\vcenter\bgroup\Let@\restore@math@cr\default@tag
 \tabskip\z@skip\baselineskip20\ex@
 \lineskip3\ex@\lineskiplimit3\ex@\halign\bgroup
 &\hfill$\m@th##$\hfill\crcr}
\def\endCD{\crcr\egroup\egroup\egroup}
%    \end{macrocode}
%
% \begin{macro}{\CD@check}
%    This check is used by all macros that must not appear outside the
%    \env{CD} environment. The first argument is the symbol to be used
%    after \verb+@+, the second one the action to be performed.
%
%    Once again we use the trick of defining a temporary control
%    sequence \verb+\next@+ and calling it after the final \verb+\fi+.
%    This is not absolutely necessary, but it ensures that the
%    conditional text is processed in one and the same column
%    of the enclosing alignment.
%    \begin{macrocode}
\def\CD@check#1#2{\ifCD@\DN@{#2}\else
  \DN@{\PackageError{amscd}{@\protect#1 not
    allowed outside of the CD environment}\@eha}%
  \fi\next@}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\atdef@>#1>#2>{\ampersand@
  \ifCD@ \global\bigaw@\minCDarrowwidth \else \global\bigaw@\minaw@ \fi
  \setboxz@h{$\m@th\scriptstyle\;{#1}\;\;$}%
  \ifdim\wdz@>\bigaw@\global\bigaw@\wdz@\fi
%    \end{macrocode}
%      If \verb|#2| is empty we can save some work.
%    \begin{macrocode}
  \@ifnotempty{#2}{\setbox\@ne\hbox{$\m@th\scriptstyle\;{#2}\;\;$}%
    \ifdim\wd\@ne>\bigaw@\global\bigaw@\wd\@ne\fi}%
 \ifCD@\enskip\fi
   \mathrel{\mathop{\hbox to\bigaw@{\rightarrowfill@\displaystyle}}%
     \limits^{#1}\@ifnotempty{#2}{_{#2}}}%
 \ifCD@\enskip\fi \ampersand@}
%
\atdef@<#1<#2<{\ampersand@
  \ifCD@ \global\bigaw@\minCDarrowwidth \else \global\bigaw@\minaw@ \fi
  \setboxz@h{$\m@th\scriptstyle\;\;{#1}\;$}%
  \ifdim\wdz@>\bigaw@ \global\bigaw@\wdz@ \fi
  \@ifnotempty{#2}{\setbox\@ne\hbox{$\m@th\scriptstyle\;\;{#2}\;$}%
    \ifdim\wd\@ne>\bigaw@ \global\bigaw@\wd\@ne \fi}%
  \ifCD@\enskip\fi
    \mathrel{\mathop{\hbox to\bigaw@{\leftarrowfill@\displaystyle}}%
      \limits^{#1}\@ifnotempty{#2}{_{#2}}}%
  \ifCD@\enskip\fi \ampersand@}
%    \end{macrocode}
%
%      Variants of the above two arrows, using \verb|(| and \verb|)|
%      characters instead of \verb|<| and \verb|>| characters, are
%      provided for those whose keyboards don't have the latter.
%    \begin{macrocode}
\begingroup \catcode`\~=\active \lccode`\~=`\@
\lowercase{%
  \global\atdef@)#1)#2){~>#1>#2>}
  \global\atdef@(#1(#2({~<#1<#2<}
}% end lowercase
\endgroup
%    \end{macrocode}
%
%    \begin{macrocode}
\atdef@ A#1A#2A{\CD@check{A..A..A}{\llap{$\m@th\vcenter{\hbox
  {$\scriptstyle#1$}}$}\Big\uparrow
  \rlap{$\m@th\vcenter{\hbox{$\scriptstyle#2$}}$}&&}}
%
\atdef@ V#1V#2V{\CD@check{V..V..V}{\llap{$\m@th\vcenter{\hbox
  {$\scriptstyle#1$}}$}\Big\downarrow
  \rlap{$\m@th\vcenter{\hbox{$\scriptstyle#2$}}$}&&}}
%
\atdef@={\CD@check={&\enskip\mathrel
  {\vbox{\hrule\@width\minCDarrowwidth\vskip2\ex@\hrule\@width
  \minCDarrowwidth}}\enskip&}}
%
\atdef@|{\CD@check|{\Big\Vert&&}}
%
\atdef@\vert{\CD@check\vert{\Big\Vert&&}}
%
\atdef@.{\CD@check.{&&}}
%    \end{macrocode}
%
%    The \cn{pretend} command has weird syntax that doesn't fit well
%    with standard \latex/ syntax so we leave it undone, at least for
%    now. [mjd,1994/10/27]
%    \begin{macrocode}
%\def\pretend#1\haswidth#2{\setboxz@h{$\m@th\scriptstyle{#2}$}\hbox
% to\wdz@{\hfill$\m@th\scriptstyle{#1}$\hfill}}
%    \end{macrocode}
%
%    The usual \cs{endinput} to ensure that random garbage at the end of
%    the file doesn't get copied by \fn{docstrip}.
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
% \CheckSum{442}
% \Finale
