%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                           %
%   newtype.sty                                                             %
%                                                                           %
%   Copyright 1995 Stuart A. Kurtz                                          %
%   All Rights Reserved                                                     %
%   --------------------------------------------------------------          %
%   The newtype macro is based on the earlier newfontobj macro.             %
%   The main utility of this macro is to make it easy to associate          %
%   a typeface with a particular type of object, as is often done           %
%   in mathematical writing.                                                %
%                                                                           %
%   For example:                                                            %
%                                                                           %
%       \newtype{\class}{\mathrm}                                           %
%       \class{P}                                                           %
%                                                                           %
%   declares \P to be \ensuremath{\mathrm{P}}\xspace.  The newly            %
%   defined \P macro can be used either in or out of math mode, in          %
%   a fairly natural way.  For example,                                     %
%                                                                           %
%       \class{NP}                                                          %
%                                                                           %
%       The class \P consists of all languages accepted by deterministic    %
%       polynomial time turing machines, while the class \NP consists of    %
%       all languages accepted by nondeterministic turing machines.         %
%       It is widely believed that these languages have different           %
%       computational power.  In particular $\NP = \NP^{\P}$ is a trivial   %
%       theorem, whereas $\P^{\NP} = \P$ is most likely false.              %
%                                                                           %
%   will typeset as expected.                                               %
%                                                                           %
%   The macro defined by newtype takes an optional form, which is           %
%   intended to enable use of this facility when the class has embedded     %
%   LaTeX commands, e.g.,                                                   %
%                                                                           %
%       \class[parityP]{\oplus P}                                           %
%                                                                           %
%   declares \parityP to be \ensuremath{\mathrm{\oplus P}}\xspace.          %
%                                                                           %
%   Finally, the it is possible to use the type macro to set a specific     %
%   expression, without introducing a new macro, by using the following     %
%   form:                                                                   %
%                                                                           %
%       \class<NC>                                                          %
%                                                                           %
%   For example,                                                            %
%                                                                           %
%       In this note, we will be considering circuit classes, such as       %
%       \class<NC>, or \class<SC>.                                          %
%                                                                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{newtype}[1995/09/01 v1.0]
\RequirePackage{xspace}

\newcommand{\newtype}[2]{\def#1{\@ifnextchar<{\@inewtype#2}{\@ifnextchar[{\@onewtype#2}{\@nnewtype#2}}}}

\def\@inewtype#1<#2>{\ensuremath{#1{#2}}}
\def\@onewtype#1[#2]#3{\expandafter\def\csname#2\endcsname{\@inewtype{#1}<#3>\xspace}}
\def\@nnewtype#1#2{\@onewtype{#1}[#2]{#2}}
