% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{rcs}
\RequirePackage{ifthen}

\RCS$Date: 1997/04/25 13:46:53 $
\RCS$RCSfile: aacategory.sty,v $
\RCS$Revision: 1.2 $
\RCS$State: OK $
\RCS$Author: anders $

\def\aabasenamex#1.#2,#3{#1}
\def\aafiletypex#1.#2,#3{#2}
\def\aabasename{\expandafter\aabasenamex\RCSRCSfile}
\ifthenelse{\equal{\@clsextension}{\expandafter\aafiletypex\RCSRCSfile}}{%
  \def\aafiletype{Class}}{%
  \def\aafiletype{Package}}
\ifthenelse{\equal{OK}{\RCSState}}{%
  \def\aastate{ }}{%
  \def\aastate{ (\RCSState) }}
\typeout{\aafiletype: `\aabasename' v\RCSRevision\aastate
  <\RCSRawDate> (\RCSAuthor)}

\NeedsTeXFormat{LaTeX2e}
\ifthenelse{\equal{\aafiletype}{Class}}{%
  \ProvidesClass{\aabasename}[\RCSRawDate]}{%
  \ProvidesPackage{\aabasename}[\RCSRawDate]}


% --------------------------------------%--------------------------------------
% -------------------------------- Description --------------------------------
% --------------------------------------%--------------------------------------

% The arrow or morphism (\arr) is an matrix arrow (\mar) from the
% aamar package (\mar is an xymatrix arrow from the xy package
% implemented by the \ar command).  You must specify a direction for
% each arrow.  You can also modify the behavior of the arrow by
% specifying an optional first argument which will be added to the \ar
% command.   An optional label can also be added.  We can use \arr to
% typeset (at least) 2 types of arrows in a xymatrix. 
%
% 1. An arrow from on object to another:
%
%   You give the direction from the current object to the other on (u
%   = up, r = right, d = down, l = left, ur/ru = up and to the right,
%   ul/lu = up and to the left, ...
% 
%   An arrow with the label f from this object to the one at the left
%   (l):
%
%         \arr{l}^{f}
%
%   The same arrow dashed:
%
%         \arr[@{-->}]{l}^{f}
%
%   An arrow without a label from this object to the one down and at
%   the right (dr):
%
%         \arr{dr}
%
% 2. An arrow back to the same object:
%
%   You put a * mark before the out and in directions.  You can give 8
%   type of directions (u, ur/ru, r, dr/rd, d, dl/ld, l, ul/lu).  The
%   first direction indicates the direction of the arrow out from the
%   object, and the second direction indicates the direction in to the
%   object. 
%
%   An clock-wise arrow with the label 1_A and with the top turning
%   point up and at the left:
%
%         \arr*{u,l}^{1_A}
%
%   An counter-wise arrow without a label and with the top turning
%   point at the right (r):
%
%         \arr*{dr,ur}
%
% There is also some almost identical commands for functors (\farr)
% and mapping (\marr).
%
% Two examples:
%
%         \[
%         \begin{xy}
%           \xymatrix{
%             A
%             \arr*{ur,ul}_{1_A}
%             \arr*{ul,dl}_{f}
%             \arr[@/^2.5ex/]{r}^{g}
%             \arr{r}|{h} 
%             \arr[@/_2ex/]{dr}_{m}
%             & B
%             \arr*{dr,ur}_{1_B}
%             \arr[@/^2.5ex/]{l}^{k}
%             \arr[@{-->}]{d}^{l} \\
%             & C
%             \arr*{dl,dr}^{1_C}
%             }
%         \end{xy}
%         \]
%
%         \[
%         \begin{xy}
%           \xymatrix{
%             A \arr*{ul,ur}^{i} \arr*{ur,dr}^{j} \arr*{dr,dl}^{k} \arr*{dl,ul}^{l}
%             & & B \arr*{r,u}_{a} \arr*{d,r}_{b} \arr*{l,d}_{c} \arr*{u,l}_{d}
%             }
%         \end{xy}
%         \]


% --------------------------------------%--------------------------------------
% -------------------------- Declaration of options ---------------------------
% --------------------------------------%--------------------------------------

\DeclareOption{ps}{%
  \PassOptionsToPackage{dvips}{xy}
  \AtEndOfPackage{\UsePSspecials{dvips}}}
\DeclareOption{dvips}{%
  \PassOptionsToPackage{dvips}{xy}
  \AtEndOfPackage{\UsePSspecials{dvips}}}


% --------------------------------------%--------------------------------------
% --------------------------- Execution of options ----------------------------
% --------------------------------------%--------------------------------------

\ExecuteOptions{mathit}
\ProcessOptions


% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{aamar}[1995/07/19]


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------

%
% Arrows used
%

% A new arrow (for functors)
\newdir{|>}{!/4.7pt/\dir{|}
  *:(1,-.2)\dir^{>}
  *:(1,+.2)\dir_{>}}

% In XY-pic, @ is active.
\makeatother

% A morphism arrow (with one optional argument to change the behavior):
\newcommand{\morphar}[1][]{\mbox{\ensuremath{\;\xy\ar#1(4,0)\endxy\;}}}
\newcommand{\lmorphar}[1][]{\mbox{\ensuremath{\;\xy\ar#1(-4,0)\endxy\;}}}

% A functor arrow (with one optional argument to change the behavior):
\newcommand{\functar}[1][]{\mbox{\ensuremath{\;\xy\ar@{-|>}#1(4,0)\endxy\;}}}
\newcommand{\lfunctar}[1][]{\mbox{\ensuremath{\;\xy\ar@{-|>}#1(-4,0)\endxy\;}}}

% A mapping arrow (with one optional argument to change the behavior):
\newcommand{\mapar}[1][]{\mbox{\ensuremath{\;\xy\ar@{|->}#1(4,0)\endxy\;}}}
\newcommand{\lmapar}[1][]{\mbox{\ensuremath{\;\xy\ar@{|->}#1(-4,0)\endxy\;}}}

% An adjunct arrow (?) (with one optional argument to change the behavior):
\newcommand{\adj}[1][]{\mbox{\ensuremath{\;\xy\ar@{-|}#1(4,0)\endxy\;}}}

% Non active @
\makeatletter

%
% Typesetting categories in the text
%

% A category (* when the name is more than a letter):
\newcommand{\cat}{\@ifnextchar*{\@wcat}{\@cat}}
\def\@cat#1{\ensuremath{\mathcal{#1}}}
\def\@wcat*#1{\ensuremath{\mathbf{#1}}}

% A dual category (* when the name is more than a letter):
\newcommand{\dcat}{\@ifnextchar*{\@wdcat}{\@dcat}}
\def\@dcat#1{\ensuremath{\mathcal{#1}^{\mbox{\textbf{\scriptsize op}}}}}
\def\@wdcat*#1{\ensuremath{\mathbf{#1}^{\mbox{\textbf{\scriptsize op}}}}}

% An object (* when the name is more than a letter):
\newcommand{\obj}{\@ifnextchar*{\@wobj}{\@obj}}
\def\@obj#1{\ensuremath{\mathnormal{#1}}}
\def\@wobj*#1{\ensuremath{\mathnormal{#1}}}

% A dual object (* when the name is more than a letter):
\newcommand{\dobj}{\@ifnextchar*{\@wdobj}{\@dobj}}
\def\@dobj#1{\ensuremath{\overline{\obj{#1}}}}
\def\@wdobj*#1{\ensuremath{\overline{\obj*{#1}}}}

% Set of objects in the category #1 (* when the name is more than a letter):
\newcommand{\objs}{\@ifnextchar*{\@wobjs}{\@objs}}
\def\@objs#1{\ensuremath{\mbox{\textbf{obj}}~\cat{#1}}}
\def\@wobjs*#1{\ensuremath{\mbox{\textbf{obj}}~\cat*{#1}}}

% A morphism or arrow (* when the name is more than a letter):
\newcommand{\morph}{\@ifnextchar*{\@wmorph}{\@morph}}
\def\@morph#1{\ensuremath{\mathnormal{#1}}}
\def\@wmorph*#1{\ensuremath{\mathnormal{#1}}}

% A dual morphism (* when the name is more than a letter):
\newcommand{\dmorph}{\@ifnextchar*{\@wdmorph}{\@dmorph}}
\def\@dmorph#1{\ensuremath{\overline{\morph{#1}}}}
\def\@wdmorph*#1{\ensuremath{\overline{\morph*{#1}}}}

% Set of morphisms in the category #1 (* when the name is more than a letter):
\newcommand{\morphs}{\@ifnextchar*{\@wmorphs}{\@morphs}}
\def\@morphs#1{\ensuremath{\mbox{\textbf{mor}}~\cat{#1}}}
\def\@wmorphs*#1{\ensuremath{\mbox{\textbf{mor}}~\cat*{#1}}}

% A typed morphism with domain #2 and codomain #3 (* when the name is
% more than a letter):
\newcommand{\tmorph}{\@ifnextchar*{\@wtmorph}{\@tmorph}}
\def\@tmorph#1#2#3{\ensuremath{\morph{#1}:\obj{#2}\morphar\obj{#3}}}
\def\@wtmorph*#1#2#3{\ensuremath{\morph*{#1}:\obj*{#2}\morphar\obj*{#3}}}

% An typed dual morphism with domain #2 and codomain #3 (* when the
% name is more than a letter):
\newcommand{\dtmorph}{\@ifnextchar*{\@wdtmorph}{\@dtmorph}}
\def\@dtmorph#1#2#3{\ensuremath{\dmorph{#1}:\dobj{#2}\morphar\dobj{#3}}}
\def\@wdtmorph*#1#2#3{\ensuremath{\dmorph*{#1}:\dobj*{#2}\morphar\dobj*{#3}}}

% A functor (* when the name is more than a letter):
\newcommand{\funct}{\@ifnextchar*{\@wfunct}{\@funct}}
\def\@funct#1{\ensuremath{\mathnormal{#1}}}
\def\@wfunct*#1{\ensuremath{\mathnormal{#1}}}

% A typed functor from category #2 to category #3 (* when the name is
% more than a letter):
\newcommand{\tfunct}{\@ifnextchar*{\@wtfunct}{\@tfunct}}
\def\@tfunct#1#2#3{\ensuremath{\funct{#1}:\cat{#2}\functar\cat{#3}}}
\def\@wtfunct*#1#2#3{\ensuremath{\funct*{#1}:\cat*{#2}\functar\cat*{#3}}}

% Composition (* when the name is more than a letter):
\newcommand{\comp}{\@ifnextchar*{\@wcomp}{\@comp}}
\def\@comp#1#2{\ensuremath{\morph{#1}\:{\circ}\:\morph{#2}}}
\def\@wcomp*#1#2{\ensuremath{\morph*{#1}\:{\circ}\:\morph*{#2}}}

% Dual composition (* when the name is more than a letter):
\newcommand{\dcomp}{\@ifnextchar*{\@wdcomp}{\@dcomp}}
\def\@dcomp#1#2{\ensuremath{\overline{\morph{#1}\:{\circ}\:\morph{#2}}}}
\def\@wdcomp*#1#2{\ensuremath{\overline{\morph*{#1}\:{\circ}\:\morph*{#2}}}}

% Mapping (values):
\newcommand{\mapping}[2]{\ensuremath{{#1}\mapar{#2}}}

% Isomorphism (* when the name is more than a letter):
\newcommand{\isomorphobj}{\@ifnextchar*{\@wisomorphobj}{\@isomorphobj}}
\def\@isomorphobj#1#2{\ensuremath{\obj{#1}\cong\obj{#2}}}
\def\@wisomorphobj*#1#2{\ensuremath{\obj*{#1}\cong\obj*{#2}}}
\newcommand{\isomorphcat}{\@ifnextchar*{\@wisomorphcat}{\@isomorphcat}}
\def\@isomorphcat#1#2{\ensuremath{\cat{#1}\cong\cat{#2}}}
\def\@wisomorphcat*#1#2{\ensuremath{\cat*{#1}\cong\cat*{#2}}}

% Exist morphism (* when the name is more than a letter):
\newcommand{\exmorph}{\@ifnextchar*{\@wexmorph}{\@exmorph}}
\def\@exmorph#1#2{\ensuremath{\obj{#1}\leq\obj{#2}}}
\def\@wexmorph*#1#2{\ensuremath{\obj{#1}\leq\obj{#2}}}

% Product (* when the name is more than a letter):
\newcommand{\product}{\@ifnextchar*{\@wproduct}{\@product}}
\def\@product#1#2{\ensuremath{\obj{#1}\times\obj{#2}}}
\def\@wproduct*#1#2{\ensuremath{\obj*{#1}\times\obj*{#2}}}

% Coproduct or sum (* when the name is more than a letter):
\newcommand{\coproduct}{\@ifnextchar*{\@wcoproduct}{\@coproduct}}
\def\@coproduct#1#2{\ensuremath{\obj{#1}+\obj{#2}}}
\def\@wcoproduct*#1#2{\ensuremath{\obj*{#1}+\obj*{#2}}}

% Product of morphism #1 and #2 (* when the name is more than a letter):
\newcommand{\prodmorph}{\@ifnextchar*{\@wprodmorph}{\@prodmorph}}
\def\@prodmorph#1#2{\ensuremath{(\morph{#1},\morph{#2})}}
\def\@wprodmorph*#1#2{\ensuremath{(\morph*{#1},\morph*{#2})}}

% Sum (coproduct) of morphism #1 and #2 (* when the name is more than
% a letter):
\newcommand{\summorph}{\@ifnextchar*{\@wsummorph}{\@summorph}}
\def\@summorph#1#2{\ensuremath{\left(\!\!\begin{array}{c}
        \morph{#1} \\ \morph{#2}
      \end{array}\!\!\right)}}
\def\@wsummorph*#1#2{\ensuremath{\left(\!\!\begin{array}{c}
        \morph*{#1} \\ \morph*{#2}
      \end{array}\!\!\right)}}

% Adjunct (* when the name is more than a letter):
\newcommand{\adjfunct}{\@ifnextchar*{\@wadjfunct}{\@adjfunct}}
\def\@adjfunct#1#2{\ensuremath{\funct{#1}\adj\funct{#2}}}
\def\@wadjfunct*#1#2{\ensuremath{\funct*{#1}\adj\funct*{#2}}}

% Exponential (* when the name is more than a letter):
\newcommand{\expobj}{\@ifnextchar*{\@wexobj}{\@expobj}}
\def\@expobj#1#2{\ensuremath{\obj{#1}^{\obj{#2}}}}
\def\@wexpobj*#1#2{\ensuremath{\obj*{#1}^{\obj*{#2}}}}
% or:
\newcommand{\altexpobj}{\@ifnextchar*{\@waltexobj}{\@altexpobj}}
\def\@altexpobj#1#2{\ensuremath{[\obj{#2}\morphar\obj{#1}]}}
\def\@waltexpobj*#1#2{\ensuremath{[\obj*{#2}\morphar\obj*{#1}]}}

% Monoid (* when the name is more than a letter):
\newcommand{\monoid}{\@ifnextchar*{\@wmonoid}{\@monoid}}
\newcommand{\@monoid}[2][xox]{%
  \ifthenelse{\equal{#1}{xox}}{\cat{#2}}{\ensuremath{(\obj{#2},#1)}}}
\def\@wmonoid*#1{\@ifnextchar[{\@@wmonoid{#1}}{\@monoid{\cat*{#1}}}}
\def\@@wmonoid[#1]#2{\@monoid[#1]{\obj*{#2}}}

%
% Typesetting categories in a xymatrix
%

% In XY-pic, @ is active.
\makeatother

% An arrow (or morphism) is just an matrix arrow (\mar):
\newcommand{\arr}{\mar}

% A functor arrow is just an matrix arrow (\mar) with the optional
% argument @{-|>}:
\newcommand{\farr}[1][]{\mar[@{-|>}#1]}

% A map arrow is just an matrix arrow (\mar) with the optional
% argument @{|->}:
\newcommand{\marr}[1][]{\mar[@{|->}#1]}

% Non active @
\makeatletter
