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