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