% Stuart's defs.sty.   [This is the most important part --KWR]
%
% Construct a "newdefinition" command analogous to the newtheorem
% command.  The primary difference is that the newdefinition widget
% does not cause its body to be italicized.
%
% This is all cribbed from latex.tex.
% Contact Stuart A. Kurtz if there are any difficulties.

\def\newdefinition#1{\@ifnextchar[{\@odefn{#1}}{\@ndefn{#1}}}

\def\@ndefn#1#2{%
\@ifnextchar[{\@xndefn{#1}{#2}}{\@yndefn{#1}{#2}}}

\def\@xndefn#1#2[#3]{\expandafter\@ifdefinable\csname #1\endcsname
{\@definecounter{#1}\@addtoreset{#1}{#3}%
\expandafter\xdef\csname the#1\endcsname{\expandafter\noexpand
  \csname the#3\endcsname \@thmcountersep \@thmcounter{#1}}%
\global\@namedef{#1}{\@defn{#1}{#2}}\global\@namedef{end#1}{\@enddefinition}}}

\def\@yndefn#1#2{\expandafter\@ifdefinable\csname #1\endcsname
{\@definecounter{#1}%
\expandafter\xdef\csname the#1\endcsname{\@thmcounter{#1}}%
\global\@namedef{#1}{\@defn{#1}{#2}}\global\@namedef{end#1}{\@enddefinition}}}

\def\@odefn#1[#2]#3{\expandafter\@ifdefinable\csname #1\endcsname
  {\global\@namedef{the#1}{\@nameuse{the#2}}%
\global\@namedef{#1}{\@defn{#2}{#3}}%
\global\@namedef{end#1}{\@enddefinition}}}

\def\@defn#1#2{\refstepcounter
    {#1}\@ifnextchar[{\@ydefn{#1}{#2}}{\@xdefn{#1}{#2}}}

\def\@xdefn#1#2{\@begindefinition{#2}{\csname the#1\endcsname}\ignorespaces}
\def\@ydefn#1#2[#3]{\@opargbegindefinition{#2}{\csname
       the#1\endcsname}{#3}\ignorespaces}


\def\@begindefinition#1#2{ \trivlist \item[\hskip \labelsep{\bf #1\ #2.}]}
\def\@opargbegindefinition#1#2#3{\trivlist
      \item[\hskip \labelsep{\bf #1\ #2\ (#3).}]}
\def\@enddefinition{\endtrivlist}


% Construct a "newscholium" command analogous to the newtheorem
% command.  The primary difference is that the newscholium widget
% does not cause its body to be italicized.
%
% This is all cribbed from latex.tex.
% Contact Stuart A. Kurtz if there are any difficulties.

\def\newscholium#1{\@ifnextchar[{\@oschm{#1}}{\@nschm{#1}}}

\def\@nschm#1#2{%
\@ifnextchar[{\@xnschm{#1}{#2}}{\@ynschm{#1}{#2}}}

\def\@xnschm#1#2[#3]{\expandafter\@ifdefinable\csname #1\endcsname
{\@definecounter{#1}\@addtoreset{#1}{#3}%
\expandafter\xdef\csname the#1\endcsname{\expandafter\noexpand
  \csname the#3\endcsname \@thmcountersep \@thmcounter{#1}}%
\global\@namedef{#1}{\@schm{#1}{#2}}\global\@namedef{end#1}{\@endscholium}}}

\def\@ynschm#1#2{\expandafter\@ifdefinable\csname #1\endcsname
{\@definecounter{#1}%
\expandafter\xdef\csname the#1\endcsname{\@thmcounter{#1}}%
\global\@namedef{#1}{\@schm{#1}{#2}}\global\@namedef{end#1}{\@endscholium}}}

\def\@oschm#1[#2]#3{\expandafter\@ifdefinable\csname #1\endcsname
  {\global\@namedef{the#1}{\@nameuse{the#2}}%
\global\@namedef{#1}{\@schm{#2}{#3}}%
\global\@namedef{end#1}{\@endscholium}}}

\def\@schm#1#2{\refstepcounter
    {#1}\@ifnextchar[{\@yschm{#1}{#2}}{\@xschm{#1}{#2}}}

\def\@xschm#1#2{\@beginscholium{#2}{\csname the#1\endcsname}\ignorespaces}
\def\@yschm#1#2[#3]{\@opargbeginscholium{#2}{\csname
       the#1\endcsname}{#3}\ignorespaces}

\def\@beginscholium#1#2{\footnotesize \trivlist %
	\item[]{\bf #1\ #2.\hskip \labelsep}} 
\def\@opargbeginscholium#1#2#3{\footnote \trivlist %
       \item[]{\bf #1\ #2\ (#3).\hskip \labelsep}}
\def\@endscholium{\endtrivlist}


%%% The \text command stolen from AMSLaTeX

\def\RIfM@{\relax\ifmmode}
\def\RIfMIfI@{\relax\ifmmode\ifinner}

\def\Invalid@#1{\def#1{\Err@{\Invalid@@\string#1}}}
\def\Invalid@@{Invalid use of }
\def\DN@{\def\next@}
\def\eat@#1{}


\def\text{\RIfM@\expandafter\text@\else\expandafter\text@@\fi}
\def\text@@#1{\leavevmode\hbox{#1}}

\newif\iffirstchoice@
\firstchoice@true
\def\text@#1{\mathchoice
 {\hbox{\everymath{\displaystyle}\def\textfonti{\the\textfont\@ne}%
  \def\textfontii{\the\textfont\tw@}\textdef@@ T#1}}
 {\hbox{\firstchoice@false
  \everymath{\textstyle}\def\textfonti{\the\textfont\@ne}%
  \def\textfontii{\the\textfont\tw@}\textdef@@ T#1}}
 {\hbox{\firstchoice@false
  \everymath{\scriptstyle}\def\textfonti{\the\scriptfont\@ne}%
  \def\textfontii{\the\scriptfont\tw@}\textdef@@ S\rm#1}}
 {\hbox{\firstchoice@false
  \everymath{\scriptscriptstyle}\def\textfonti
  {\the\scriptscriptfont\@ne}%
  \def\textfontii{\the\scriptscriptfont\tw@}\textdef@@ s\rm#1}}}
\def\textdef@@#1{\textdef@#1\rm\textdef@#1\bf\textdef@#1\sl\textdef@#1\it}
\def\rmfam{0}
\def\textdef@#1#2{%
 \DN@{\csname\expandafter\eat@\string#2fam\endcsname}%
 \if S#1\edef#2{\the\scriptfont\next@\relax}%
 \else\if s#1\edef#2{\the\scriptscriptfont\next@\relax}%
 \else\edef#2{\the\textfont\next@\relax}\fi\fi}
