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