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