| 1 | % \begin{meta-comment} |
| 2 | % |
| 3 | % $Id: mdwthm.dtx,v 1.5 2003/12/01 00:47:56 mdw Exp $ |
| 4 | % |
| 5 | % Standard theorem typesetting |
| 6 | % |
| 7 | % (c) 2001 Mark Wooding |
| 8 | % |
| 9 | % \end{meta-comment} |
| 10 | % |
| 11 | % \begin{meta-comment} <general public licence> |
| 12 | %% |
| 13 | %% mdwthm package -- standard theorem stuff |
| 14 | %% Copyright (c) 2001 Mark Wooding |
| 15 | %% |
| 16 | %% This program is free software; you can redistribute it and/or modify |
| 17 | %% it under the terms of the GNU General Public License as published by |
| 18 | %% the Free Software Foundation; either version 2 of the License, or |
| 19 | %% (at your option) any later version. |
| 20 | %% |
| 21 | %% This program is distributed in the hope that it will be useful, |
| 22 | %% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | %% GNU General Public License for more details. |
| 25 | %% |
| 26 | %% You should have received a copy of the GNU General Public License |
| 27 | %% along with this program; if not, write to the Free Software Foundation, |
| 28 | %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 29 | % \end{meta-comment} |
| 30 | % |
| 31 | % \begin{meta-comment} <Package preambles> |
| 32 | %<+package>\NeedsTeXFormat{LaTeX2e} |
| 33 | %<+package>\ProvidesPackage{mdwthm} |
| 34 | %<+package> [2001/09/16 1.0 theorem typesetting] |
| 35 | %<+thmstyle>\ProvidesFile{mdwmargin.thm} |
| 36 | %<+thmstyle> [2001/09/16 1.0 numbers-in-the-margin theorem style] |
| 37 | % \end{meta-comment} |
| 38 | % |
| 39 | % \CheckSum{204} |
| 40 | %% \CharacterTable |
| 41 | %% {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 |
| 42 | %% 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 |
| 43 | %% Digits \0\1\2\3\4\5\6\7\8\9 |
| 44 | %% Exclamation \! Double quote \" Hash (number) \# |
| 45 | %% Dollar \$ Percent \% Ampersand \& |
| 46 | %% Acute accent \' Left paren \( Right paren \) |
| 47 | %% Asterisk \* Plus \+ Comma \, |
| 48 | %% Minus \- Point \. Solidus \/ |
| 49 | %% Colon \: Semicolon \; Less than \< |
| 50 | %% Equals \= Greater than \> Question mark \? |
| 51 | %% Commercial at \@ Left bracket \[ Backslash \\ |
| 52 | %% Right bracket \] Circumflex \^ Underscore \_ |
| 53 | %% Grave accent \` Left brace \{ Vertical bar \| |
| 54 | %% Right brace \} Tilde \~} |
| 55 | %% |
| 56 | % |
| 57 | % \begin{meta-comment} |
| 58 | % |
| 59 | %<*driver> |
| 60 | \input{mdwtools} |
| 61 | \describespackage{mdwthm} |
| 62 | \mdwdoc |
| 63 | %</driver> |
| 64 | % |
| 65 | % \end{meta-comment} |
| 66 | % |
| 67 | %^^A------------------------------------------------------------------------- |
| 68 | % \section{User guide} |
| 69 | % |
| 70 | % \subsection{Environments provided} |
| 71 | % |
| 72 | % \DescribeEnv{theorem} |
| 73 | % \DescribeEnv{lemma} |
| 74 | % \DescribeEnv{proposition} |
| 75 | % \DescribeEnv{corollary} |
| 76 | % \DescribeEnv{definition} |
| 77 | % \DescribeEnv{example} |
| 78 | % \DescribeEnv{fact} |
| 79 | % \DescribeEnv{remark} |
| 80 | % \DescribeEnv{note} |
| 81 | % The package defines a collection of theorem environments, declared in the |
| 82 | % usual way. All of them except \env{claim} share the same counter. If the |
| 83 | % document class has a |\chapter| command, then they are numbered within the |
| 84 | % chapter; otherwise there is a single numbering system throughout the |
| 85 | % document. |
| 86 | % |
| 87 | % Every environment has a $*$-version, which doesn't print a number. This |
| 88 | % might be useful every now and then. |
| 89 | % |
| 90 | % The environments \env{theorem}, \env{lemma}, \env{proposition}, |
| 91 | % \env{claim}and \env{corollary} are set using the `plain' style, with the |
| 92 | % body text in \textit{italics}. The environments \env{definition} and |
| 93 | % \env{example} are set in the `definition' style, with body text in roman. |
| 94 | % The remaining environments, \env{fact}, \env{remark}, and \env{note} are |
| 95 | % set in the `remark' style. |
| 96 | % |
| 97 | % \DescribeEnv{claim} |
| 98 | % \DescribeEnv{proof} |
| 99 | % The \env{claim} environment has its own counter, which is reset at the |
| 100 | % beginning of the \env{proof} environment. If you say |\qed| in a |
| 101 | % \env{proof} environment then it uses your symbol; otherwise it adds its own |
| 102 | % at the end. |
| 103 | % |
| 104 | % \subsection{Options} |
| 105 | % |
| 106 | % The package takes an option \syntax{"within="<counter>} -- number theorems |
| 107 | % within \<counter>. If this isn't given, a default is chosen -- either |
| 108 | % numbering in chapters, or global numbering. The \lit*{notwithin} option |
| 109 | % forces global numbering. |
| 110 | % |
| 111 | % \subsection{The \package{mdwmargin} style} |
| 112 | % |
| 113 | % This package also provides a pretty `number-hanging-in-the-margin' theorem |
| 114 | % style collection, available under the name \env{mdwmargin}. |
| 115 | % |
| 116 | % \implementation |
| 117 | % |
| 118 | % |
| 119 | %^^A------------------------------------------------------------------------- |
| 120 | % \section{Implementation of the environments} |
| 121 | % |
| 122 | % \begin{macrocode} |
| 123 | %<*package> |
| 124 | \RequirePackage{mdwkey} |
| 125 | \if1% |
| 126 | \ifx\if@article\iftrue0 |
| 127 | \else\ifx\chapter\@@undefined0 |
| 128 | \else\ifx\chapter\relax0 |
| 129 | \else1\fi\fi\fi |
| 130 | \def\mt@within{[chapter]} |
| 131 | \else |
| 132 | \def\mt@within{} |
| 133 | \fi |
| 134 | \mkdef{mdwthm:opt}{within}{\def\mt@within{[#1]}} |
| 135 | \mkdef{mdwthm:opt}{notwithin}*{\def\mt@within{}} |
| 136 | \mkdef*{mdwthm:opt}{\PassOptionsToPackage{#1=#2}{amsthm}} |
| 137 | \mkdef*{mdwthm:opt}*{\PassOptionsToPackage{#1}{amsthm}} |
| 138 | \def\mt@opt#1{\mkparse{mdwthm:opt}{#1}} |
| 139 | \DeclareOption*{\expandafter\mt@opt\expandafter{\CurrentOption}} |
| 140 | \ProcessOptions |
| 141 | \RequirePackage{amsthm} |
| 142 | % \end{macrocode} |
| 143 | % |
| 144 | % \subsection{The simple bits} |
| 145 | % |
| 146 | % \begin{environment}{theorem} |
| 147 | % |
| 148 | % Do the right thing with the numbering rules. |
| 149 | % |
| 150 | % \begin{macrocode} |
| 151 | \edef\next@{\noexpand\newtheorem{theorem}{Theorem}\mt@within}\next@ |
| 152 | \newtheorem*{theorem*}{Theorem} |
| 153 | % \end{macrocode} |
| 154 | % |
| 155 | % \end{environment} |
| 156 | % |
| 157 | % \begin{environment}{lemma} |
| 158 | % \begin{environment}{proposition} |
| 159 | % \begin{environment}{corollary} |
| 160 | % \begin{environment}{claim} |
| 161 | % \begin{environment}{definition} |
| 162 | % \begin{environment}{example} |
| 163 | % \begin{environment}{fact} |
| 164 | % \begin{environment}{remark} |
| 165 | % |
| 166 | % Most of this is very easy. |
| 167 | % |
| 168 | % \begin{macrocode} |
| 169 | \theoremstyle{plain} |
| 170 | \newtheorem{lemma}[theorem]{Lemma} |
| 171 | \newtheorem*{lemma*}{Lemma} |
| 172 | \newtheorem{proposition}[theorem]{Proposition} |
| 173 | \newtheorem*{proposition*}{Proposition} |
| 174 | \newtheorem{corollary}[theorem]{Corollary} |
| 175 | \newtheorem*{corollary*}{Corollary} |
| 176 | \newtheorem{fact}[theorem]{Fact} |
| 177 | \newtheorem*{fact*}{Fact} |
| 178 | \newtheorem{claim}{Claim} |
| 179 | \newtheorem*{claim*}{Claim} |
| 180 | % \end{macrocode} |
| 181 | % |
| 182 | % \begin{macrocode} |
| 183 | \theoremstyle{definition} |
| 184 | \newtheorem{definition}[theorem]{Definition} |
| 185 | \newtheorem*{definition*}{Definition} |
| 186 | \newtheorem{example}[theorem]{Example} |
| 187 | \newtheorem*{example*}{Example} |
| 188 | % \end{macrocode} |
| 189 | % |
| 190 | % \begin{macrocode} |
| 191 | \theoremstyle{remark} |
| 192 | \newtheorem{remark}[theorem]{Remark} |
| 193 | \newtheorem*{remark*}{Remark} |
| 194 | % \end{macrocode} |
| 195 | % |
| 196 | % \end{environment} |
| 197 | % \end{environment} |
| 198 | % \end{environment} |
| 199 | % \end{environment} |
| 200 | % \end{environment} |
| 201 | % \end{environment} |
| 202 | % \end{environment} |
| 203 | % \end{environment} |
| 204 | % |
| 205 | % \begin{environment}{note} |
| 206 | % |
| 207 | % Someone else might also have a \env{note} environment. Be careful. |
| 208 | % |
| 209 | % \begin{macrocode} |
| 210 | \ifx\note\@@undefined |
| 211 | \newtheorem{note}[theorem]{Note} |
| 212 | \newtheorem*{note*}{Note} |
| 213 | \fi |
| 214 | % \end{macrocode} |
| 215 | % |
| 216 | % \end{environment} |
| 217 | % |
| 218 | % \begin{macro}{\@qedhack} |
| 219 | % |
| 220 | % Make |\qed| idempotent. |
| 221 | % |
| 222 | % \begin{macrocode} |
| 223 | \newif\if@qedsw |
| 224 | \def\@qedhack{% |
| 225 | \let\@qed@\qed% |
| 226 | \global\@qedswtrue% |
| 227 | \def\qed{\if@qedsw\global\@qedswfalse\expandafter\@qed@\fi}% |
| 228 | } |
| 229 | % \end{macrocode} |
| 230 | % |
| 231 | % \end{macro} |
| 232 | % |
| 233 | % \begin{environment}{proof} |
| 234 | % |
| 235 | % Now to hack the proof environment. |
| 236 | % |
| 237 | % \begin{macrocode} |
| 238 | \renewenvironment{proof}[1][\proofname]{% |
| 239 | \setcounter{claim}{0}% |
| 240 | \par\normalfont% |
| 241 | \ifdim\topsep<\parskip\topsep\parskip\fi% |
| 242 | \ifdim\@topsepadd<\z@\@topsepadd\z@\fi% |
| 243 | \trivlist\advance\itemindent\labelsep\let\makelabel\proofstyle% |
| 244 | \advance\@topsep-\parskip% |
| 245 | \advance\@topsepadd-\parskip% |
| 246 | \@qedhack% |
| 247 | \item[#1]% |
| 248 | }{% |
| 249 | \qed\endtrivlist% |
| 250 | } |
| 251 | % \end{macrocode} |
| 252 | % \end{environment} |
| 253 | % |
| 254 | % \begin{macro}{\proofstyle} |
| 255 | % |
| 256 | % The |\proofstyle| macro is just a style hook for typesetting the `Proof' |
| 257 | % label. |
| 258 | % |
| 259 | % \begin{macrocode} |
| 260 | \providecommand\proofstyle[1]{\textit{#1.}} |
| 261 | % \end{macrocode} |
| 262 | % |
| 263 | % \end{macro} |
| 264 | % |
| 265 | % Done. |
| 266 | % |
| 267 | % \begin{macrocode} |
| 268 | %</package> |
| 269 | % \end{macrocode} |
| 270 | % |
| 271 | %^^A------------------------------------------------------------------------- |
| 272 | % \section{Implementation of the theorem style} |
| 273 | % |
| 274 | % \begin{macrocode} |
| 275 | %<*thmstyle> |
| 276 | % \end{macrocode} |
| 277 | % |
| 278 | % \begin{macro}{\thmhead@margin} |
| 279 | % |
| 280 | % Firstly, a macro to typeset the theorem environment header, with the number |
| 281 | % in the margin. |
| 282 | % |
| 283 | % \begin{macrocode} |
| 284 | \def\thmhead@margin#1#2#3{% |
| 285 | \thmnumber{\llap{#2{\normalsize\quad}}}% |
| 286 | \thmname{#1}% |
| 287 | \thmnote{ \the\thm@notefont(#3)}% |
| 288 | } |
| 289 | % \end{macrocode} |
| 290 | % \end{macro} |
| 291 | % |
| 292 | % \begin{macro}{\thm@headfont@margin} |
| 293 | % |
| 294 | % Now to decide on the header font. Definitely we want boldface; if the |
| 295 | % documentclass (or \package{mdwfonts}) has decided on a different font |
| 296 | % family for the headings, then we use that. |
| 297 | % |
| 298 | % \begin{macrocode} |
| 299 | \def\thm@headfont@margin{% |
| 300 | \fontseries{\bfdefault}% |
| 301 | \ifx\headdefault\@@undfined\else\fontfamily\headdefault\fi% |
| 302 | \selectfont% |
| 303 | } |
| 304 | % \end{macrocode} |
| 305 | % \end{macro} |
| 306 | % |
| 307 | % \begin{macro}{\qedsymbol} |
| 308 | % |
| 309 | % Use the nice symbol if available. |
| 310 | % |
| 311 | % \begin{macrocode} |
| 312 | \AtBeginDocument{\ifx\square\@@undefined\else\def\qedsymbol{$\square$}\fi} |
| 313 | % \end{macrocode} |
| 314 | % \end{macro} |
| 315 | % |
| 316 | % \begin{macro}{\proofstyle} |
| 317 | % |
| 318 | % Typeset `Proof' in bold face. |
| 319 | % |
| 320 | % \begin{macrocode} |
| 321 | \def\proofstyle#1{{\thm@headfont@margin#1}} |
| 322 | % \end{macrocode} |
| 323 | % |
| 324 | % \end{macro} |
| 325 | % |
| 326 | % \begin{macro}{\th@base} |
| 327 | % \begin{macro}{\@endtheorem} |
| 328 | % |
| 329 | % The |\th@base| macro provides the basis for our theorem style. The |
| 330 | % argument is something to do at the end of the environment. |
| 331 | % |
| 332 | % \begin{macrocode} |
| 333 | \def\th@base#1{% |
| 334 | \let\thmhead\thmhead@margin% |
| 335 | \thm@headfont{\thm@headfont@margin}% |
| 336 | \thm@headpunct{}% |
| 337 | \advance\thm@postskip-\parskip% |
| 338 | \@qedhack% |
| 339 | \def\after@thm{#1}% |
| 340 | \normalfont% |
| 341 | } |
| 342 | % \end{macrocode} |
| 343 | % |
| 344 | % Ah, but nobody actually does anything with |\after@thm|. Let's fix that. |
| 345 | % |
| 346 | % \begin{macrocode} |
| 347 | \AtEndOfPackage{\def\@endtheorem{\after@thm\endtrivlist}} |
| 348 | % \end{macrocode} |
| 349 | % \end{macro} |
| 350 | % \end{macro} |
| 351 | % |
| 352 | % \begin{macro}{\th@plain} |
| 353 | % \begin{macro}{\th@definition} |
| 354 | % \begin{macro}{\th@remark} |
| 355 | % |
| 356 | % Now this is easy. The space hacking in |\th@remark| is straight from |
| 357 | % \package{amsthm}. |
| 358 | % |
| 359 | % \begin{macrocode} |
| 360 | \AtBeginDocument{ |
| 361 | \def\th@plain{\th@base\relax\itshape} |
| 362 | \def\th@definition{\th@base\qed} |
| 363 | \def\th@remark{% |
| 364 | \th@base\qed% |
| 365 | \thm@preskip\topsep\divide\thm@preskip\tw@% |
| 366 | \thm@postskip\thm@preskip% |
| 367 | } |
| 368 | } |
| 369 | %</thmstyle> |
| 370 | % \end{macrocode} |
| 371 | % \end{macro} |
| 372 | % \end{macro} |
| 373 | % \end{macro} |
| 374 | % |
| 375 | % \hfill Mark Wooding, \today |
| 376 | % \Finale |
| 377 | % |
| 378 | \endinput |