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