% \begin{meta-comment}
%
-% $Id: mdwthm.dtx,v 1.3 2003/09/05 16:16:20 mdw Exp $
+% $Id: mdwthm.dtx,v 1.5 2003/12/01 00:47:56 mdw Exp $
%
% Standard theorem typesetting
%
% (c) 2001 Mark Wooding
%
-%----- Revision history -----------------------------------------------------
-%
-% $Log: mdwthm.dtx,v $
-% Revision 1.3 2003/09/05 16:16:20 mdw
-% Various nips and tucks. Redefine theorem styles from scratch now.
-%
-% Revision 1.2 2002/02/24 12:35:55 mdw
-% Fix handling of \chapter, in case some idiot has said `\csname
-% chapter\endcsname'.
-%
-% Revision 1.1 2002/02/03 20:49:03 mdw
-% Checkin for new build system.
-%
-%
% \end{meta-comment}
%
% \begin{meta-comment} <general public licence>
%<+thmstyle> [2001/09/16 1.0 numbers-in-the-margin theorem style]
% \end{meta-comment}
%
-% \CheckSum{187}
+% \CheckSum{204}
%% \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
% \env{proof} environment then it uses your symbol; otherwise it adds its own
% at the end.
%
+% \subsection{Options}
+%
+% The package takes an option \syntax{"within="<counter>} -- number theorems
+% within \<counter>. If this isn't given, a default is chosen -- either
+% numbering in chapters, or global numbering. The \lit*{notwithin} option
+% forces global numbering.
+%
% \subsection{The \package{mdwmargin} style}
%
% This package also provides a pretty `number-hanging-in-the-margin' theorem
%
% \begin{macrocode}
%<*package>
-\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{amsthm}}
-\ProcessOptions\relax
+\RequirePackage{mdwkey}
+\if1%
+ \ifx\if@article\iftrue0
+ \else\ifx\chapter\@@undefined0
+ \else\ifx\chapter\relax0
+ \else1\fi\fi\fi
+ \def\mt@within{[chapter]}
+\else
+ \def\mt@within{}
+\fi
+\mkdef{mdwthm:opt}{within}{\def\mt@within{[#1]}}
+\mkdef{mdwthm:opt}{notwithin}*{\def\mt@within{}}
+\mkdef*{mdwthm:opt}{\PassOptionsToPackage{#1=#2}{amsthm}}
+\mkdef*{mdwthm:opt}*{\PassOptionsToPackage{#1}{amsthm}}
+\def\mt@opt#1{\mkparse{mdwthm:opt}{#1}}
+\DeclareOption*{\expandafter\mt@opt\expandafter{\CurrentOption}}
+\ProcessOptions
\RequirePackage{amsthm}
% \end{macrocode}
%
% Do the right thing with the numbering rules.
%
% \begin{macrocode}
-\toks@{\newtheorem{theorem}{Theorem}}
-\@tempswatrue%
-\ifx\if@article\iftrue\@tempswafalse\fi
-\ifx\chapter\@@undefined\@tempswafalse\fi
-\ifx\chapter\relax\@tempswafalse\fi
-\if@tempswa\toks@\expandafter{\the\toks@[chapter]}\fi
-\the\toks@
+\edef\next@{\noexpand\newtheorem{theorem}{Theorem}\mt@within}\next@
\newtheorem*{theorem*}{Theorem}
% \end{macrocode}
%
% Ah, but nobody actually does anything with |\after@thm|. Let's fix that.
%
% \begin{macrocode}
-\def\@endtheorem{\after@thm\endtrivlist\@endpefalse}
+\AtEndOfPackage{\def\@endtheorem{\after@thm\endtrivlist}}
% \end{macrocode}
% \end{macro}
% \end{macro}