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