Debian Codegraph @

texmf-dist/source/latex/phfthm/phfthm.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2016 by Philippe Faist, [email protected]
4 % -------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{phfthm.dtx}
21 %</driver>
22 %<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
23 %<package>\ProvidesPackage{phfthm}
24 %<*package>
25 [2021/03/01 v1.2 phfthm package]
26 %</package>
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \usepackage{xcolor}
31 \usepackage{phfthm}
32 \usepackage[preset=xpkgdoc]{phfnote}
33 \usepackage{needspace}
34 \expandafter\def\csname eqsign@\endcsname{=}
35 \def\eqsign{\expandafter\protect\csname eqsign@\endcsname}
36 \robustify\eqsign
37 \EnableCrossrefs
38 \CodelineIndex
39 \RecordChanges
40 \begin{document}
41 \DocInput{phfthm.dtx}
42 \end{document}
43 %</driver>
44 % \fi
45 %
46 % \CheckSum{0}
47 %
48 % \CharacterTable
49 % {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
50 % 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
51 % Digits \0\1\2\3\4\5\6\7\8\9
52 % Exclamation \! Double quote \" Hash (number) \#
53 % Dollar \$ Percent \% Ampersand \&
54 % Acute accent \' Left paren \( Right paren \)
55 % Asterisk \* Plus \+ Comma \,
56 % Minus \- Point \. Solidus \/
57 % Colon \: Semicolon \; Less than \<
58 % Equals \= Greater than \> Question mark \?
59 % Commercial at \@ Left bracket \[ Backslash \\
60 % Right bracket \] Circumflex \^ Underscore \_
61 % Grave accent \` Left brace \{ Vertical bar \|
62 % Right brace \} Tilde \~}
63 %
64 %
65 % \changes{v1.0}{2016/04/20}{Initial version}
66 %
67 % \GetFileInfo{phfthm.dtx}
68 %
69 % \DoNotIndex{\newcommand,\newenvironment,\def,\gdef,\edef,\xdef,\if,\else,\fi,\ifx}
70 % \DoNotIndex{\expandafter,\csname,\endcsname,\let}
71 %
72 % \title{\phfqitltxPkgTitle{phfthm}}
73 % \author{Philippe Faist\quad\email{[email protected]}}
74 % \date{\pkgfmtdate\filedate}
75 % \maketitle
76 %
77 % \begin{abstract}
78 % \pkgname{phfthm}---Goodies for theorems and proofs.
79 % \end{abstract}
80 %
81 % \inlinetoc
82 %
83 % \section{Introduction}
84 %
85 % The \pkgname{phfthm} package provides enhanced theorem and proof environments,
86 % based on the \pkgname{amsthm} original versions. It allows for hooks to be
87 % placed, adds some default goodies and is highly customizable.
88 %
89 % There are three generic types of environments provided: theorem environments,
90 % proof environments and ``thmheading'' environments.
91 %
92 % \subsection{Theorem environments}
93 %
94 % Theorem environments look like this:
95 % \begingroup\setlength{\fboxsep}{1ex}
96 % \par\noindent\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
97 % \begin{theorem}[Gauss]\noproofref
98 % \label{thm:example-Gauss}
99 % For a closed surface $S$ enclosing a volume $V$, we have
100 % \begin{equation}
101 % \oint_S\vec u\cdot d\vec S = \int_V(\vec\nabla\cdot\vec u)\,dV\ .
102 % \end{equation}
103 % \end{theorem}
104 % \end{minipage}}\endgroup
105 %
106 % \subsection{Proof environments}
107 %
108 % A proof environment might look like this:
109 % \begingroup\setlength{\fboxsep}{1ex}
110 % \par\noindent\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
111 % \begin{proof}[*thm:example-Gauss]
112 % The proof of the theorem goes here. \par\ldots
113 % \end{proof}
114 % \end{minipage}}\endgroup
115 %
116 % The enhanced theorem and proof environments provided by this package allow to
117 % pair theorems with proofs, automatically generating references from one to the
118 % other (see \autoref{sec:proof-ref-mechanism}).
119 %
120 %
121 % \subsection{Theorem-heading environments}
122 %
123 % Finally, theorem-heading environments are formatted like theorems, but the
124 % heading title is set as an argument to the environment. These environments
125 % are a nice alternative for definitions, and look like this:
126 % \begingroup\setlength{\fboxsep}{1ex}
127 % \par\noindent\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
128 % \begin{thmheading}{Trace Distance}
129 % The `trace distance' between $\rho$ and $\sigma$ is defined as
130 % \begin{equation}
131 % \delta(\rho,\sigma)=\frac12\,\left\Vert \rho - \sigma \right\Vert_1\ ,
132 % \end{equation}
133 % where $\lVert\cdot\rVert_1$ is the Schatten-1 norm.
134 % \end{thmheading}
135 % \end{minipage}}\endgroup
136 %
137 %
138 %
139 % \section{Quick start and package options}
140 % \label{sec:quick-start}
141 % \label{sec:global-pkg-options}
142 %
143 % Example: Load the rich theorem set, with separate counters, and with proof-ref
144 % mechanism on and always displaying the proof reference in the margin:
145 % \begin{verbatim}
146 % \usepackage[thmset=rich,sepcounters=true,proofref={always,margin}]{phfthm}
147 % \end{verbatim}
148 %
149 % By default, some styles are tweaked a bit so that they appear nicely as
150 % documented below (for example, by using a filled square instead of a simple
151 % square for end-of-proof QED markers). Use the package option
152 % \pkgoptionfmt{resetstyle} to instruct \pkgname{phfthm} not to proceed to these
153 % style adjustments; this allows you to enable features individually and
154 % selectively:
155 % \begin{verbatim}
156 % \usepackage[resetstyle,prooftitleitbf=true]{phfthm}
157 % \end{verbatim}
158 %
159 %
160 % \subsection{Predefined theorem environments}
161 % \label{sec:theorem-sets}
162 %
163 % You may load predefined theorem sets via the package option
164 % \pkgoptionfmt{thmset}. Theorem sets group common environments used in
165 % mathematical works such as Theorem, Proposition, Definition, etc.
166 %
167 % Some package options control the way these environments are defined. If you
168 % would like more refined control over the appearance of these environments, or
169 % over which environments are defined, you may consider calling |\phfLoadThmSet|
170 % manually or defining individual environments with |\phfMakeTheorem|.
171 %
172 % Possible theorem sets are:
173 % \begin{pkgoptions}
174 % \item[thmset=,thmset=empty] Do not define any environment at package loading.
175 % You may of course invoke |\phfLoadThmSet| or |\phfMakeTheorem| manually at
176 % any later point.
177 % \item[thmset=simple]
178 % \DescribeEnv{theorem} \DescribeEnv{proposition}
179 % \DescribeEnv{lemma} \DescribeEnv{corollary} \DescribeEnv{definition}
180 % Define the environments |theorem|, |proposition|, |lemma|
181 % and |corollary| as theorem-like environments, and |definition| as a
182 % definition-like environment.
183 % \item[thmset=default] \DescribeEnv{conjecture} \DescribeEnv{remark} Define the
184 % environments |theorem|, |proposition|, |lemma|, |corollary|, |conjecture|,
185 % |remark| as theorem-like environments, and |definition| as a definition-like
186 % environment.
187 % \item[thmset=shortnames] \iffalse\DescribeEnv{thm}\DescribeEnv{prop}
188 % \DescribeEnv{lem}\DescribeEnv{cor}\DescribeEnv{conj}\DescribeEnv{rem}
189 % \DescribeEnv{defn}\fi In case you prefer to type less: the same environments
190 % are defined as the default set, but with shorter names. Define the
191 % environments |thm|, |prop|, |lem|, |cor|, |conj|, |rem| as theorem-like
192 % environments, and |defn| as a definition-like environment.
193 % \item[thmset=rich] \DescribeEnv{idea} \DescribeEnv{question}
194 % \DescribeEnv{claim} \DescribeEnv{observation} \DescribeEnv{problem} Provides
195 % the same environments as the |default| theorem set, as well as in addition:
196 % |idea|, |question|, |claim|, |observation|, and |problem| as theorem-like
197 % environments.
198 % \end{pkgoptions}
199 %
200 % You may also load a theorem set at a later
201 % point after loading the \pkgname{phfthm} package by invoking the
202 % |\phfLoadThmSet| macro, see \autoref{sec:load-thm-set-manually}.
203 %
204 % Further package options modify the style of the theorem-like and
205 % definition-like environments defined via the \pkgoptionfmt{thmset} package
206 % option:
207 %
208 % \begin{pkgoptions}
209 % \item[theoremstyle=\meta{theorem style name}] Use this package option to
210 % specify which style to use for theorem-like environments when loading the
211 % theorem set specified via the \pkgoptionfmt{thmset} package option. The
212 % theorem style name should be one of |plain|, |definition|, |remark|, or any
213 % other |\newtheoremstyle|-defined theorem style (see documentation of
214 % \pkgname{amsthm}).
215 % \item[definitionstyle=\meta{theorem style name}] Use this package option to
216 % specify which style to use for definition-like environments when loading the
217 % theorem set specified via the \pkgoptionfmt{thmset} package option. The
218 % theorem style name should be one of |plain|, |definition|, |remark|, or any
219 % other |\newtheoremstyle|-defined theorem style (see documentation of
220 % \pkgname{amsthm}).
221 % \end{pkgoptions}
222 %
223 % Further options control various aspects of the environments defined by
224 % \pkgoptionfmt{thmset}.
225 % \begin{pkgoptions}
226 % \item[sepcounters=\metatruefalsearg] Each theorem environment defined with the
227 % \pkgoptionfmt{thmset} package option will use a separate counter if this
228 % option is set; otherwise (the default), there is a single counter which is
229 % shared by all those theorem environments.
230 % \item[parentcounter=\meta{counter name}] Theorem counters will reset each time
231 % the parent counter is increased. Use this option for per-chapter or
232 % per-section numbering (use parent counter |parentcounter=chapter| or
233 % |parentcounter=section|). See also the \pkgoptionfmt{countpersection}
234 % package option.
235 % \end{pkgoptions}
236 %
237 % The \pkgoptionfmt{proofref} package option allows to specify a comma-separated
238 % list of attributes to apply to the proof reference (``proof on page XYZ'')
239 % displayed along with the theorem. The following attributes may be specified:
240 % \begin{pkgoptions}
241 % \item[proofref=\pkgoptattribempty{},proofref=\pkgoptattribnodots{default}] Do
242 % not change the default proof reference appearance.
243 %
244 % \item[proofref=false] Deactivate the proof-ref mechanism.
245 %
246 % \item[proofref=\pkgoptattrib{margin}] The proof reference is displayed in
247 % the margin, instead of after the theorem.
248 %
249 % \item[proofref=\pkgoptattrib{marginbottom}] The proof reference is displayed
250 % in the margin, but aligned with the bottom of the theorem statement.
251 %
252 % \item[proofref=\pkgoptattrib{longref}] The proof reference is displayed as
253 % a full sentence (``The proof of this \meta{Theorem Name} can be found on
254 % page \meta{XYZ}.'').
255 %
256 % \item[proofref=\pkgoptattrib{off}] Turn off the proof reference mechanism
257 % completely for theorems defined with the \pkgoptionfmt{thmset} option.
258 %
259 % \item[proofref=\pkgoptattrib{always}] Always display the proof reference,
260 % even if the proof is on the same page or on a nearby page.
261 %
262 % Note: this option has a global effect.
263 %
264 % \item[proofref=\pkgoptattrib{onyifveryfar}] The proof reference is only
265 % displayed if the proof is at least two pages back, or four pages ahead.
266 %
267 % Note: this option has a global effect.
268 %
269 % \end{pkgoptions}
270 %
271 % \begin{pkgnote}
272 % The two package options \pkgoptionfmt{proofref=\pkgoptattribnodots{always}}
273 % and \pkgoptionfmt{proofref=\pkgoptattribnodots{onlyifveryfar}} apply to
274 % \emph{all} theorem environments which use the proof-ref mechanism, whether
275 % they have already been defined or not (see |\phfProofrefPageBackTolerance|
276 % and |\phfProofrefPageAheadTolerance|).
277 %
278 % All the other above options apply only to the theorem environments defined
279 % via the \pkgoptionfmt{thmset} package option.
280 % \end{pkgnote}
281 %
282 % \subsection{The proof environment}
283 % \label{sec:proof-env}
284 %
285 % \DescribeEnv{proof}
286 % By default, the \pkgname{phfthm} package overrides the |proof| environment
287 % with a the package's own enhanced version. If you want to preserve the
288 % original \emph{AMS} environment, you should use the
289 % \pkgoptionfmt{proofenv=false} package option.
290 %
291 % \begin{pkgoptions}
292 % \item[proofenv=\metatruefalsearg] If set to |true|, then define an enhanced
293 % |proof| environment when loading this package. This will override any
294 % previously existing |proof| environment such as \emph{AMS}'.
295 %
296 % If set to |false|, no action is taken at package loading time. You should
297 % then directly use the |\phfMakeProofEnv| macro to define proof environments.
298 % \end{pkgoptions}
299 %
300 % If you want finer control over how the proof environment is defined, or if you
301 % want to customize its appearance, you should use the |\phfMakeProofEnv| macro
302 % directly (\autoref{sec:mk-proof-env}).
303 %
304 % If you set \pkgoptionfmt{proofenv=true}, there are a couple package options
305 % which alter the way the proof displays:
306 % \begin{pkgoptions}
307 % \item[smallproofs=\metatruefalsearg] If set to |true|, then proofs display in
308 % a smaller font.
309 %
310 % \item[qedsymbolblacksquare=\metatruefalsearg] If set to |true|, the QED
311 % end-of-proof symbol (usually ``$\square$'' with \pkgname{amsthm}) is
312 % replaced by a filled square (``$\blacksquare$'').
313 %
314 % \item[prooftitleitbf=\metatruefalsearg] If set to |true|, then the proof title
315 % (``Proof'' or ``Proof of Theorem 1'') is typeset in bold italic font.
316 % \end{pkgoptions}
317 %
318 %
319 % \subsection{The theorem-heading environment}
320 % \label{sec:thmheading-default}
321 % \DescribeEnv{thmheading} By default, the |thmheading| environment is provided
322 % by the \pkgname{phfthm} package:
323 % \begin{verbatim}
324 % \begin{thmheading}{Trace Distance}
325 % The `trace distance' between $\rho$ and $\sigma$ is defined as
326 % \begin{equation}
327 % \delta(\rho,\sigma)=\frac12\,\left\Vert\rho-\sigma\right\Vert_1\ ,
328 % \end{equation}
329 % where $\lVert\cdot\rVert_1$ is the Schatten-1 norm.
330 % \end{thmheading}
331 % \end{verbatim}
332 % \begingroup\setlength{\fboxsep}{1ex}
333 % \par\noindent\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
334 % \begin{thmheading}{Trace Distance}
335 % The `trace distance' between $\rho$ and $\sigma$ is defined as
336 % \begin{equation}
337 % \delta(\rho,\sigma)=\frac12\,\left\Vert \rho - \sigma \right\Vert_1\ ,
338 % \end{equation}
339 % where $\lVert\cdot\rVert_1$ is the Schatten-1 norm.
340 % \end{thmheading}
341 % \end{minipage}}\endgroup
342 %
343 % You may also use |\label| and |\ref| as usual (|\ref| simply displays the
344 % given title).
345 %
346 % Some package options control the way this environment is defined.
347 %
348 % \begin{pkgoptions}
349 % \item[thmheading=\metatruefalsearg] Define the environment
350 % |\begin{thmheading}...\end{thmheading}| when loading the \pkgname{phfthm}
351 % package, with reasonable default settings.
352 % \item[thmheadingstyle=\meta{theorem style}] If \pkgoptionfmt{thmheading=true}
353 % was specified, you may use this option to specify the theorem style to use
354 % for the |thmheading| environment. Possible values are \emph{AMS} theorem
355 % style names (e.g.\@ the base styles |plain|, |definition| or |remark|), or
356 % any other style defined with |\newtheoremstyle|.
357 % \end{pkgoptions}
358 %
359 % If you want to define theorem-heading environments manually, see
360 % \autoref{sec:thmheading-manually}.
361 %
362 %
363 %
364 %
365 % \section{Theorem environments}
366 %
367 % A theorem environment is based on the environment furnished by
368 % \pkgname{amsthm}'s |\newtheorem| command, but with added goodies.
369 %
370 %
371 % \subsection{Define theorem environments manually}
372 %
373 % \DescribeMacro{\phfMakeTheorem} If you don't want to load a full theorem set
374 % (\autoref{sec:theorem-sets}), you can define theorem environments individually
375 % with |\phfMakeTheorem|:
376 %
377 % \noindent |\phfMakeTheorem|\hspace{0pt}\oarg{key-value
378 % options}\hspace{0pt}\marg{theorem environment name}\hspace{0pt}\marg{theorem
379 % name}
380 %
381 % This command defines a new environment (given as the first mandatory argument)
382 % which behaves as a theorem and is displayed as given by the second mandatory
383 % argument. For example, we might call |\phfMakeTheorem{theorem}{Theorem}| to
384 % define the environment |\begin{theorem}...\end{theorem}| which displays
385 % ``\textit{Theorem N.} \ldots''
386 %
387 % The possible key-value options for the optional argument are:
388 % \begin{cmdoptions}
389 % \item[counter=\meta{\LaTeX{} counter $\mid$ (empty)}] The name of the \LaTeX{}
390 % counter to use for the theorem environment. If this is empty, then a new
391 % counter will be created which is specific to this theorem environment (the
392 % default). If not empty, then the theorem environment uses the given counter
393 % (or an alias thereof, see \cmdoptionfmt{aliascounter}).
394 %
395 % If a counter is specified, the counter should already be defined with
396 % \LaTeX's |\newcounter|.
397 %
398 % \item[aliascounter=\metatruefalsearg] In some cases
399 % (e.g.\@ if you're using \pkgname{hyperref}'s |\autoref|), it is important to
400 % have counters specific to each theorem environment (so you get ``Theorem 5''
401 % or ``Proposition 5'' right). However, you may want different theorem
402 % environments to share a same logical counter (Say ``Definition 1'',
403 % ``Definition 2'', ``Theorem 3'', ``Proposition 4''). In this case, you
404 % should specify \cmdoptionfmt{aliascounter=true}.
405 %
406 % When this option is on, then first we define an alias counter of the one
407 % given to the \cmdoptionfmt{counter} option, and then use the alias for the
408 % theorem environment. The alias is declared using the \pkgname{aliascnt}
409 % package. The alias counter is automatically set up correctly for using
410 % |\autoref|.
411 %
412 % Note that the \cmdoptionfmt{aliascounter} option only has an effect if the
413 % \cmdoptionfmt{counter} option is set to some non-empty value. If
414 % \cmdoptionfmt{counter} is set to a non-empty value, then
415 % \cmdoptionfmt{aliascounter} defaults to |true|.
416 %
417 % \item[thmstyle=\meta{theorem style $\mid$ (empty)}] The theorem style to use
418 % to define this theorem environment. The value of this option should be a
419 % valid argument to \textit{AMS}'s |\theoremstyle|. If you leave this empty
420 % (the default), then the theorem style is not set explicitly and whatever
421 % default style is used.
422 %
423 % \item[defnostar=\metatruefalsearg] Set this to
424 % |true| if you want the corresponding non-starred theorem environment to be
425 % defined, e.g.\@ |\begin{theorem}...\end{theorem}|.
426 %
427 % Normal (non-starred) versions of the environments have an associated theorem
428 % number, as you expect by default.
429 %
430 % \item[defstar=\metatruefalsearg] Set this to
431 % |true| if you want the corresponding starred theorem environment to be
432 % defined, e.g.\@ |\begin{theorem*}...\end{theorem*}|.
433 %
434 % Starred versions of the environments do not have an associated theorem
435 % number.
436 %
437 % \item[proofref=\metatruefalsearg] Enable or disable
438 % the proof-ref mechanism for this theorem environment (enabled by default).
439 %
440 % \item[proofrefstyle=\meta{proof-ref style}] The style to use for the proof
441 % references. Here you may specify how the proof ref appears, for example (in
442 % the margin, long sentence, ...). Possible styles are
443 % \cmdoptionfmt{proofrefstyle=default} (the default),
444 % \cmdoptionfmt{proofrefstyle=margin} (display the proof ref in the margin of
445 % the page), \cmdoptionfmt{proofrefstyle=marginbottom} (display the proof ref
446 % in the margin of the page aligned with the bottom of the theorem statement)
447 % and \cmdoptionfmt{proofrefstyle=longref} (as by default but with a full
448 % sentence). See \autoref{sec:proof-ref-customize-appearance} for how to
449 % further customize the appearance of the proof reference.
450 %
451 % \end{cmdoptions}
452 %
453 % For example, you may use the following command invocation to define a theorem
454 % environment named ``Remark'' implemented as |\begin{remark}...\end{remark}|,
455 % also with a starred verison |\begin{remark*}...\end{remark*}|, using the
456 % |plain| \emph{AMS} theorem style, and without the proof-ref mechanism:
457 % \begin{verbatim}
458 % \phfMakeTheorem[defstar=true,defnostar=true,thmstyle=plain,counter=,%
459 % proofref=false]{remark}{Remark}
460 % \end{verbatim}
461 %
462 %
463 %
464 % \subsection{Loading theorem sets manually}
465 % \label{sec:load-thm-set-manually}
466 %
467 % \DescribeMacro{\phfLoadThmSet} You may load theorem sets at any time via the
468 % macro |\phfLoadThmSet|. This may be useful, for example, to load theorem sets
469 % only after you have defined a custom theorem style. The syntax of
470 % |\phfLoadThmSet| is:
471 %
472 % \noindent |\phfLoadThmSet|\hspace{0pt}\marg{options to
473 % \phfverb{\phfMakeTheorem} for theorem-like
474 % environments}\hspace{0pt}\marg{options to \phfverb{\phfMakeTheorem} for
475 % definition-like environments}\hspace{0pt}\marg{name of theorem set to load}
476 %
477 % The first and second argument to this macro are tokens to expand in front of
478 % |\phfMakeTheorem| for theorem-like or definition-like environments. For
479 % example:
480 % \begin{verbatim}
481 % \newcounter{mythmcounter}
482 % \newtheoremstyle{mythmstyle}{...}
483 % \newtheoremstyle{mydefnstyle}{...}
484 % \phfLoadThmSet{[thmstyle=mythmstyle,counter=mythmcounter]}
485 % {[thmstyle=mydefnstyle,counter=mythmcounter]}{rich}
486 % \end{verbatim}
487 %
488 % \begin{pkgwarning}
489 % The first and second arguments to |\phfLoadThmSet| must either be empty,
490 % or be enclosed in square braces.
491 % \end{pkgwarning}
492 %
493 % \needspace{10\baselineskip}
494 % \DescribeMacro{\theoremname}
495 % \DescribeMacro{\propositionname}
496 % \DescribeMacro{\lemmaname}
497 % \DescribeMacro{\corollaryname}
498 % \DescribeMacro{\conjecturename}
499 % The title of the theorem environments defined in theorem sets use the same
500 % scheme as figures, tables, etc.\@ with regard to translations and
501 % \pkgname{babel}: they use |\theoremname|, |\propositionname|, etc.
502 %
503 % \DescribeMacro{\remarkname}
504 % \DescribeMacro{\definitionname}
505 % \DescribeMacro{\ideaname}
506 % \DescribeMacro{\questionname}
507 % \DescribeMacro{\claimname}
508 % \DescribeMacro{\problemname}
509 %
510 % This package is language agnostic (with titles defined by default in English),
511 % and does not provide the titles for other languages. In order to support
512 % language switching with \pkgname{babel} and |\selectlanguage|, you should add
513 % the relevant names to the corresponding |\captions|\meta{language name} macro,
514 % for example:
515 % \begin{verbatim}
516 % \usepackage[french,...]{babel}
517 % ...
518 % \addto\captionsfrench{%
519 % \def\theoremname{Th\'eor\`eme}%
520 % \def\propositionname{Proposition}%
521 % \def\lemmaname{Lemme}%
522 % \def\corollaryname{Corollaire}%
523 % \def\conjecturename{Conjecture}%
524 % \def\remarkname{Remarque}%
525 % \def\definitionname{D\'efinition}%
526 % \def\ideaname{Id\'ee}%
527 % \def\questionname{Question}%
528 % \def\claimname{Affirmation}%
529 % \def\problemname{Probl\`eme}%
530 % }
531 % ... \selectlanguage{french} ...
532 % \end{verbatim}
533 %
534 %
535 % \subsection{Theorem hooks}
536 % \label{sec:theorem-hooks}
537 %
538 % Any theorem environment automatically calls some hooks. There are hooks
539 % available per theorem environment as well as generic for all theorem
540 % environments.
541 %
542 % \DescribeMacro{\phfthm@hook@start@thmname} The hook
543 % |\phfthm@hook@start@|\meta{theorem environment name}\marg{theorem title} is
544 % called at the start of the environment. More precisely, it is called inside
545 % the original \pkgname{amsthm} base environment; that is, after the heading was
546 % generated. It takes one mandatory argument, the optional title provided to
547 % the theorem environment which may be empty. By default, the hook defers to
548 % the global hook |\phfthm@hook@startcommonnostar|.
549 %
550 % \DescribeMacro{\phfthm@hook@start@thmname*} The hook
551 % |\phfthm@hook@start@|\meta{starred theorem environment name} is completely
552 % analogous, and is called for the starred environment. The only difference is
553 % that by default, it defers its call to |\phfthm@hook@startcommonstar|.
554 %
555 % \DescribeMacro{\phfthm@hook@startcommonnostar} The hook
556 % |\phfthm@hook@startcommonnostar|\marg{theorem environment name}\marg{theorem
557 % optional given title} collects the default definitions for non-starred
558 % environments (none by default) and continues to defer to
559 % \DescribeMacro{\phfthm@hook@startcommon}
560 % |\phfthm@hook@startcommon|\marg{theorem environment name}\marg{theorem
561 % optional given title}. \DescribeMacro{\phfthm@hook@startcommonstar}
562 % Analogously, the macro |\phfthm@hook@startcommonstar|\marg{theorem environment
563 % name}\marg{theorem optional given title} groups commands for starred
564 % environments (typically doesn't take care of |\label| stuff) and also defers
565 % to |\phfthm@hook@startcommon|.
566 %
567 % The end hooks work very much
568 % analogously. \DescribeMacro{\phfthm@hook@end@thmname}
569 % |\phfthm@hook@end@|\meta{theorem environment name} and
570 % \DescribeMacro{\phfthm@hook@end@thmname*} |\phfthm@hook@end@|\meta{starred
571 % theorem environment name} are called respectively for the non-starred and
572 % starred version of that theorem environment, and by default they defer to the
573 % common \DescribeMacro{\phfthm@hook@endcommonnostar}
574 % |\phfthm@hook@endcommonnostar|\marg{theorem environment name} or
575 % \DescribeMacro{\phfthm@hook@endcommonstar}
576 % |\phfthm@hook@endcommonstar|\marg{theorem environment name}. Both these hooks
577 % defer their calls to |\phfthm@hook@endcommon|\marg{theorem environment name}.
578 %
579 % For theorems using the proof-reference mechanism, i.e.\@ for which
580 % \cmdoptionfmt{proofref=true} was specified to |\phfMakeTheorem| and which uses
581 % the |\label| hack (\autoref{sec:proof-ref-mechanism}), there is an additional
582 % hook. \DescribeMacro{\phfthm@hook@afterlabel@thmname} The hook
583 % |\phfthm@hook@afterlabel@|\meta{theorem environment name} is called just after
584 % the |\label| command corresponding to the theorem is encountered (this should
585 % always be at the \emph{beginning} of the theorem, see
586 % \autoref{sec:proof-ref-mechanism}). Depending on the proof-ref style, this
587 % hook may be used to generate the proof reference text (for example, with the
588 % |margin| proof-ref style). The hook is called after the theorem label is set.
589 % The label itself can be recovered from the value of the macro
590 % |\phfthm@val@thmlabel|. By default, that hook calls the common hook
591 % \DescribeMacro{\phfthm@hook@afterlabelcommon}
592 % |\phfthm@hook@afterlabelcommon|\marg{theorem environment name}. (After the
593 % first occurrence of the command |\label|, the latter's definition is
594 % restored.)
595 %
596 %
597 %
598 % \section{Proof environments}
599 %
600 % Proof environments typeset mathematical proofs. The proof environment(s)
601 % provided by \pkgname{phfthm} give some added functionality with respect to the
602 % \emph{AMS}-default |proof| environment, such as supporting the proof-reference
603 % mechanism described in \autoref{sec:proof-ref-mechanism}.
604 %
605 % A proof environment might look like the following:
606 % \begin{proof}[Theorem 5]
607 % Let $\mathcal{T}_{X\to X'}$ be any trace nonincreasing completely positive
608 % map such that $\mathcal{T}_{X\to X'}\left(\Gamma_X\right)$ lies within the
609 % support of $\Gamma_{X'}$. Define the normalized state
610 % $\gamma_X = \Gamma_X / \operatorname{tr}\Gamma_X$.
611 %
612 % Now consider this and that \ldots
613 % \end{proof}
614 %
615 %
616 % The proof environments defined by this package wrap a given proof display
617 % environment (such as \emph{AMS}' (\pkgname{amsthm}'s) or \pkgname{IEEEtran}'s
618 % original |proof| environment) by adding functionality in the form of hooks.
619 % In the following, we refer to the ``underlying proof display environment'' as
620 % the original environment which is wrapped. It may be any \LaTeX{} environment
621 % whose task is to format the proof nicely.
622 %
623 %
624 % \subsection{Manually define a proof environment}
625 % \label{sec:mk-proof-env}
626 %
627 % \DescribeMacro{\phfMakeProofEnv} You may use the macro |\phfMakeProofEnv| to
628 % declare a new proof environment. The syntax is:
629 %
630 % \noindent |\phfMakeProofEnv|\oarg{key-value options}\marg{proof environment name}
631 %
632 % This defines a new environment with the given name, which may be used to
633 % display proofs to theorems. The options may be:
634 % \begin{cmdoptions}
635 % \item[displayenv=\meta{name of \LaTeX{} environment}] Set a
636 % \LaTeX{} environment to use to actually format and display the proof. (The
637 % |\phfMakeProofEnv| command itself doesn't care about how the proof is
638 % displayed or formatted; rather it adds a goodies infrastructure in which
639 % stuff can be plugged in and provides options for such goodies.)
640 %
641 % You may specify here the name of a \LaTeX{} environment, or give the special
642 % value \cmdoptionfmt{displayenv=*} to indicate the default appearance
643 % provided by \pkgname{phfthm}, or leave the value empty
644 % \cmdoptionfmt{displayenv=} to signify that no underlying display environment
645 % should be invoked. (The latter may be useful if you are plugging a
646 % |\phfMakeProofEnv|-generated environment into a larger environment which
647 % already takes care of the display.)
648 %
649 % \item[defaultproofname=\meta{default proof title}] Specify here the title to
650 % use (e.g.\@ ``Proof'') if no argument was given to the proof environment.
651 % If you do not specify any |defaultproofname|, or pass an empty value, then
652 % the value of |\proofname| is used.
653 %
654 % \item[parselabel=\metatruefalsearg] Specify whether
655 % the environment should parse its argument for some special information. If
656 % set to |true|, then the proof argument is passed on to a command (specified
657 % by the \cmdoptionfmt{parselabelcmd} option).
658 %
659 % \item[parselabelcmd=\meta{{\LaTeX} macro}] If \cmdoptionfmt{parselabel} is set
660 % to |true|, then specify here a \LaTeX{} command which parses whatever it
661 % wants from the proof environment's argument. The macro should set the
662 % |\phfthm@val@displayargs| macro to tokens which will be expanded just after
663 % the invocation of the proof environment's display environment
664 % (\cmdoptionfmt{displayenv}). It should also set |\phfthm@val@proofoflabel|
665 % (if appropriate) to the label corresponding to the theorem for which this is
666 % the proof of.
667 %
668 % By default, the command |\phfthm@proof@parselabel| is used, which parses the
669 % proof environment's argument for a reference to a theorem in the context of
670 % a proof-ref mechanism (see \autoref{sec:proof-ref-mechanism}). The label is
671 % parsed to see if it is of the form |[*thm:reference]|, where |thm:reference|
672 % is the label pinned to a theorem.
673 %
674 % \item[override=\metatruefalsearg] Whether to
675 % override any existing environment with the same name as the new proof
676 % environment. If |true| is specified here, then |\renewenvironment| is used
677 % to define the proof environment, otherwise a simple |\newenvironment| is
678 % used.
679 %
680 % \item[internalcounter=\meta{name of \LaTeX{} counter}] The name of the
681 % internal counter the proof environment should use. The count number is not
682 % displayed (by default at least), but it is only used to pin down anchors for
683 % PDF hyperlinks.
684 %
685 % The counter should already be defined with |\newcounter|.
686 %
687 % \item[proofofname=\meta{\LaTeX{} macro}] Specify here a macro
688 % which will be called with a single argument. The macro produces the text to
689 % display when the proof environment is parsed as the proof of a specific
690 % theorem or proposition (or other theorem environment). The argument which
691 % will be given to it is the title of what the proof is of (e.g.\@ ``Theorem
692 % 3''). Typically, the macro should produce something like ``Proof of Theorem
693 % XYZ.''
694 %
695 % By default, the global macro |\proofofname| is used.
696 % \end{cmdoptions}
697 %
698 % \DescribeMacro{\proofname} Text to use to display ``Proof.'' This should be
699 % already defined by the \LaTeX{} system, and \pkgname{babel} should already
700 % provide translations in different languages.
701 %
702 % \DescribeMacro{\proofofname} The globally defined macro |\proofofname|
703 % specifies the default way of displaying ``Proof of Theorem~5.'' It is
704 % originally defined as something like
705 % \begin{verbatim}
706 % \newcommand\proofofname[1]{\proofname{} of #1}
707 % \end{verbatim}
708 % You may override this to obtain something fancier, of you wish to display the
709 % document in a different language. For instance, you might want to display
710 % (``D\'emonstration (Th\'eor\`eme 5)'' in french:
711 % \begin{verbatim}
712 % \def\proofofnameinparentheses#1{\proofname\ (#1)}
713 % \addto\captionsfrench{%
714 % \def\proofname{D\'emonstration}%
715 % \let\proofofname\proofofnameinparentheses%
716 % }
717 % ...
718 % \selectlanguage{french} ...
719 % \end{verbatim}
720 %
721 %
722 %
723 % \subsection{Proof hooks}
724 % \label{sec:proof-hooks}
725 %
726 % The proof hooks are relatively straightforward. All hooks presented here take
727 % no argument.
728 %
729 % Information about the argument of the proof, both the raw argument and the
730 % possibly parsed reference, are available as macros to some of the hooks (but
731 % don't change these values unless you know what you're doing). The macro
732 % |\phfthm@val@proofarg| contains the raw argument to the proof environment, and
733 % is available to all hooks. If you use the default proof environment argument
734 % parsing (which you must have enabled when calling |\phfMakeProofEnv|), then
735 % additionally the macros |\phfthm@val@prooftitle| and |\phfthm@val@proofofname|
736 % are available containing, respectively, the label of the theorem which is
737 % referenced, and the displayable reference to it (e.g. ``Theorem~5''). The
738 % last two macros are available to all hooks except the first one (|..@start|).
739 %
740 % The hooks named |..@start...| are called within the call to
741 % |\beg||in{<proof environment>}|.
742 %
743 % \expandafter\DescribeMacro\expandafter{\csname phfthm@hookproof@...@start\endcsname}
744 % The hook named |\phfthm@hookproof@|\meta{environment name}|@start| is called
745 % at the very beginning of the proof environment.
746 %
747 % \expandafter\DescribeMacro\expandafter{\csname phfthm@hookproof@...@startafterdisplay\endcsname}
748 %
749 % The hook named |\phfthm@hookproof@|\meta{environment name}|@startafterdisplay|
750 % is invoked immediately after the beginning of the underlying ``display''
751 % environment (the environment used to display the proof contents).
752 %
753 % \expandafter\DescribeMacro\expandafter{\csname phfthm@hookproof@...@startlast\endcsname}
754 %
755 % The hook named |\phfthm@hookproof@|\meta{environment name}|@startlast| is
756 % called after we are sure that an anchor has been pinned down for the proof.
757 % This hook is called last within the commands in |\beg||in{<proof environment>}|.
758 %
759 % \DescribeMacro{\phfPinProofAnchor} By the way, the macro |\phfPinProofAnchor|
760 % may be used within the hooks to pin down an anchor for referring to the proof
761 % (especially via the proof-ref mechanism). Just call it anywhere appropriate
762 % (a good idea is calling it after leaving v-mode before displaying the title,
763 % in order to avoid placing it just before a page break). If you do not call
764 % this macro, it is automatically called for you just before the |...@startlast|
765 % hook.
766 %
767 %
768 % The two following hooks are called within the call to%
769 % |\en||d{<proof environment>}|.
770 %
771 % \expandafter\DescribeMacro\expandafter{\csname phfthm@hookproof@...@end\endcsname}
772 % The hook |\phfthm@hookproof@|\meta{environment name}|@end| is called before
773 % the proof display environment is closed.
774 %
775 % \expandafter\DescribeMacro\expandafter{\csname phfthm@hookproof@...@final\endcsname}
776 % The hook |\phfthm@hookproof@|\meta{environment name}|@final| is called after
777 % the proof environment display is finished, as the very last.
778 %
779 % All proof hooks call are defined by default to defer their call to a common
780 % hook. The common hooks each take one argument (the proof environment name).
781 % They are named |\phfthm@hookproof@startcommon|\marg{environment name},
782 % |\phfthm@hookproof@startafterdisplaycommon|\marg{environment name},
783 % |\phfthm@hookproof@startlastcommon|\marg{environment name},
784 % |\phfthm@hookproof@endcommon|\marg{environment name}, and
785 % |\phfthm@hookproof@finalcommon|\marg{environment name}.
786 % They are all defined to be empty by default.
787 %
788 %
789 % \section{Pairing theorems to proofs and proof-reference mechanism}
790 % \label{sec:proof-ref-mechanism}
791 %
792 % One of the goodies provided by the \pkgname{phfthm} package is the proof-ref
793 % mechanism, where in a theorem environment, the text ``see proof on page
794 % \ldots'' is displayed to direct the reader to the location of the
795 % corresponding proof. The mechanism is deactivated by default, but can be
796 % enabled with a simple package option.
797 %
798 % This only works if the proof is given the label of the corresponding theorem
799 % or proposition. For example:
800 % \begin{verbatim}
801 % \begin{theorem}[Gauss]
802 % \label{thm:Gauss}
803 % For a closed surface $S$ enclosing a volume $V$, we have
804 % \begin{equation}
805 % \oint_S\vec u\cdot d\vec S = \int_V(\vec\nabla\cdot\vec u)\,dV\ .
806 % \end{equation}
807 % \end{theorem}
808 %
809 % ...
810 %
811 % \begin{proof}[*thm:Gauss]
812 % ...
813 % \end{proof}
814 % \end{verbatim}
815 %
816 % The above example might produce the following output:
817 % \begingroup\setlength{\fboxsep}{1em}
818 % \par\noindent\fbox{%
819 % \begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
820 % \textbf{Theorem 17} (Gauss). For a closed surface $S$ enclosing a
821 % volume $V$, we have
822 % \begin{equation}
823 % \oint_S\vec u\cdot d\vec S = \int_V(\vec\nabla\cdot\vec u)\,dV\ .
824 % \tag*{(41)}
825 % \end{equation}
826 % \hfill{\small\itshape (Proof on page XXX.)}\hfilneg
827 % {\par\vspace{1ex}\relax
828 % \ldots\par\vspace{1ex}}\relax
829 % \par\textit{Proof of Theorem 17.}\hspace{2em}\ldots
830 % \end{minipage}
831 % }\endgroup
832 %
833 % A positive side-effect is that in your LaTeX source, if you consistently
834 % label your proofs then you always know what theorem a proof refers to. If
835 % you would like to simply output ``Proof.'' instead of ``Proof of Theorem
836 % X.'', for instance, because the proof immediately succeeds the theorem in
837 % question, you may use the syntax |[**thm:label]| instead. In this case, the
838 % proof-reference mechanism will know that this is the proof of the theorem
839 % labeled |thm:label| and will avoid undefined references. For example,
840 % the following code:
841 % \begin{verbatim}
842 % \begin{theorem}[Gauss]
843 % \label{thm:Gauss}
844 % For a closed surface $S$ enclosing a volume $V$, we have
845 % \begin{equation}
846 % \oint_S\vec u\cdot d\vec S = \int_V(\vec\nabla\cdot\vec u)\,dV\ .
847 % \end{equation}
848 % \end{theorem}
849 % \begin{proof}[**thm:Gauss]
850 % ...
851 % \end{proof}
852 % \end{verbatim}
853 % might output:
854 % \begingroup\setlength{\fboxsep}{1em}
855 % \par\noindent\fbox{%
856 % \begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
857 % \textbf{Theorem 17} (Gauss). For a closed surface $S$ enclosing a
858 % volume $V$, we have
859 % \begin{equation}
860 % \oint_S\vec u\cdot d\vec S = \int_V(\vec\nabla\cdot\vec u)\,dV\ .
861 % \tag*{(41)}
862 % \end{equation}
863 % \par\textit{Proof.}\hspace{2em}\ldots
864 % \end{minipage}
865 % }\endgroup
866 %
867 %
868 % \subsection{On the theorem side}
869 %
870 % On the theorem side, the proof-ref mechanism works by hacking into the
871 % definition of \LaTeX's |\label|. The |\label| command should be placed first
872 % within the theorem (see example above). It is important, in theorems which
873 % use the proof-ref mechanism (on by default), to always have a corresponding
874 % label: Indeed, you may experience weird results if you don't have a theorem
875 % label, but then have labels for other objects in the theorem such as equations
876 % or itemize items.
877 %
878 % Once the corresponding proof is detected (a proof environment with an optional
879 % argument of the form |[*thm:the-label]| for the same label |thm:the-label| as
880 % specified to the theorem, see \autoref{sec:proof-ref-mechanism-proof-side}),
881 % then a text is generated (by default ``Proof on page \ldots'') and placed
882 % after the theorem. The appearance of this text is customizable
883 % (\autoref{sec:proof-ref-customize-appearance}).
884 %
885 % More precisely, the hack with the |\label| command works as follows: At the
886 % beginning of the theorem, the |\label| command is redefined so that at its
887 % fist occurrence, it stores its argument as the theorem's label to use for the
888 % proof reference, it then pins down a \LaTeX{} label as the original |\label|
889 % command would do, and finally it calls the |...@afterlabel| theorem hook (see
890 % \ref{sec:theorem-hooks}). After the first occurrence of |\label|, the
891 % |\label| command is restored to its original \LaTeX{} meaning in case there
892 % are other objects within the theorem which are to be referred to.
893 %
894 % \begin{pkgtip}
895 % The |\label| hack is only active within theorem environments where the
896 % proof-ref mechanism has been enabled. Outside these environments, the
897 % |\label| macro retains its original \LaTeX{} definition.
898 % \end{pkgtip}
899 %
900 % \DescribeMacro{\noproofref} If, for any reason, you do not want to make sure
901 % you don't have any text ``Proof on page \ldots'' appearing (for example there
902 % is no corresponding proof because the theorem is obvious), then you should
903 % call |\noproofref| immediately inside the theorem:
904 % \begin{verbatim}
905 % \begin{theorem}
906 % \noproofref
907 % Theorem text ...
908 % \end{theorem}
909 % \end{verbatim}
910 %
911 % The command |\noproofref| temporarily disables the proof-ref mechanism (and
912 % restores |\label| to \LaTeX's original meaning) for the current theorem.
913 %
914 %
915 % \subsection{On the proof side}
916 % \label{sec:proof-ref-mechanism-proof-side}
917 %
918 % On the proof side, you just need to specify for which theorem this is the
919 % proof of. For that (unless you override the defaults and plug in your own
920 % magic parsing; see \autoref{sec:mk-proof-env}), you should specify an optional
921 % argument to the proof which is of the following form:
922 % |\begin{proof}[*|\meta{label}|]|,
923 % \iffalse meta-comment \end{proof} [-- emacs is confused] \fi
924 % where \meta{label} is the label name you have associated with the theorem in
925 % question (see example above).
926 %
927 % This has two effects: it sets the proof to display ``\textit{Proof of
928 % \ldots},'' and also does some background dark magic to display, at the
929 % location of the corresponding theorem, some text like ``\textit{Proof on page
930 % \ldots},'' where the page number corresponds to the page on which this proof
931 % is located.
932 %
933 % You may also use the syntax |\begin{proof}[**|\meta{label}|]|, which has the
934 % effect of producing the simple output ``Proof.'' (this is desirable e.g.\@
935 % if the proof immediately follows the theorem statement) but which still
936 % informs the proof-reference mechanism that this proof is associated with the
937 % given theorem labeled by \meta{label}. This can avoid undefined references,
938 % and can simplify your job if you want to move proofs around in your document.
939 %
940 % (It would be nice, of course, to have the package automatically output
941 % ``Proof'' only if the proof immediately follows the theorem and output ``Proof
942 % of XXX'' if the proof is further away. Unfortunately this is hard to detect
943 % in \LaTeX\ and I currently have no plans to try to implement this.)
944 %
945 % \subsection{Customizing appearance of the proof reference text}
946 % \label{sec:proof-ref-customize-appearance}
947 %
948 % Here we explain the workings of the |\phfthm@proofrefstyle@...| macros and how
949 % they are called. It allows you to define new proof-ref styles, for example.
950 %
951 % When the option \cmdoptionfmt{proofref=true} is given to |\phfMakeTheorem| to
952 % define an environment (say |mytheoremenv|), then the hook
953 % |phfthm@hook@start@mytheoremenv| will automatically include the following
954 % calls:
955 % \begin{itemize}
956 % \item The macro |\phfthm@proofrefstyle@|\meta{proof-ref style}|@setup| is called
957 % (for the proof-ref style given via the
958 % \cmdoptionfmt{proofenvstyle=\meta{style name}} key-value option to
959 % |\phfMakeTheorem|);
960 % \item The macro |\phfthm@def@label@thmlabel| is invoked, implementing the hack
961 % on the |\label| macro;
962 % \item The macro |\phfthm@proofref@impl@start| is called. This macro is
963 % expected to be defined after calling |\phfthm@proofrefstyle@|\meta{proof-ref
964 % style}|@setup|.
965 % \end{itemize}
966 %
967 % Furthermore, the |\phfthm@hook@afterlabel@mytheoremenv| hook will include a
968 % call to |\phfthm@proofref@impl@afterlabel|\marg{label of the theorem}. Again,
969 % the latter macro is expected to be defined after calling
970 % |\phfthm@proofrefstyle@|\meta{proof-ref style}|@setup|.
971 %
972 % Finally, the hook |\phfthm@hook@end@mytheoremenv| includes a call to
973 % |\phfthm@proofref@impl@end|\marg{label of the theorem}. Again,
974 % the latter macro is expected to be defined after calling
975 % |\phfthm@proofrefstyle@|\meta{proof-ref style}|@setup|.
976 %
977 %
978 % Hence, to define a new proof-ref style, you simply need to define a macro
979 % called |\phfthm@proofrefstyle@<PROOF-REF-STYLE-NAME>@setup|. This macro
980 % should include commands to locally define the macros
981 % |\phfthm@proofref@impl@start|, |\phfthm@proofref@impl@afterlabel|, and
982 % |\phfthm@proofref@impl@end|.
983 %
984 %
985 % Different proof-ref styles may work similarly and want to share most of the
986 % code. A good idea is to build up on the |default| proof-ref style, which is
987 % highly modular and can be instantiated in different flavors. For an example,
988 % check the |margin| proof-ref style which does precisely that. For more
989 % documentation, check out the implementation of the |default| proof-ref style
990 % in \autoref{sec:impl-default-proof-ref-style}.
991 %
992 %
993 %
994 %
995 % \section{Theorem-heading definition-like environments}
996 % \label{sec:thmheading}
997 %
998 % A theorem-heading environment is an environment which displays in the same way
999 % as a theorem environment, but where the title may be any text (say, ``Trace
1000 % Distance'' instead of, e.g., ``Theorem~5'').
1001 %
1002 % By default, the \pkgname{phfthm} package provides the |thmheading| environment
1003 % (see \autoref{sec:thmheading-default}).
1004 %
1005 %
1006 % \subsection{Define theorem-heading environments manually}
1007 % \label{sec:thmheading-manually}
1008 %
1009 % \DescribeMacro{\phfMakeThmheadingEnvironment} A new theorem-heading
1010 % environment can be defined by calling |\phfMakeThmheadingEnvironment|.
1011 % The syntax is:
1012 %
1013 % \noindent |\phfMakeThmheadingEnvironment|\oarg{key-value options}\marg{environment name}
1014 %
1015 % The key-value options may be any combination of the following:
1016 % \begin{cmdoptions}
1017 % \item[thmstyle=\meta{theorem style name}] The theorem style to use to display
1018 % the environment. You may specify here any default \emph{AMS} style
1019 % (|plain|, |remark| or |definition|), or any other |\newtheoremstyle|-defined
1020 % style.
1021 % \item[internalcounter=\meta{name of counter}] The name of a counter which will
1022 % internally track environment instances. By default, a common internal
1023 % counter is used for all theorem-heading environments (named
1024 % |phfthmheadingcounter|). The counter must be already defined (see \LaTeX's
1025 % |\newcounter|).
1026 % \end{cmdoptions}
1027 %
1028 %
1029 % You can also use |\label| and |\ref| (the latter simply displays the given
1030 % title).
1031 %
1032 % \subsection{Available hooks for theorem-heading environments}
1033 %
1034 % The hook |\phfthm@hook@thmheading@...@start|\marg{title} is invoked at start,
1035 % within an internal environment created with |\newtheorem|. This hook accepts
1036 % one argument, the title of the theorem-heading.
1037 %
1038 % The hook |\phfthm@hook@thmheading@...@end| is called at the end, but still
1039 % within the internal theorem environment.
1040 %
1041 % Replace the dots with the name of the theorem-heading environment (such as
1042 % |thmheading|).
1043 %
1044 % By default, these hooks simply call the common hooks
1045 % |\phfthm@hook@thmheading@start| and |\phfthm@hook@thmheading@end|. These
1046 % common hooks are empty by default.
1047 %
1048 %
1049 %
1050 %
1051 %
1052 % \StopEventually{\PrintChangesAndIndex}
1053 %
1054 %
1055 %
1056 % \section{Implementation}
1057 % \label{sec:implementation}
1058 %
1059 % First, load some packages. General toolboxes:
1060 % \begin{macrocode}
1061 \RequirePackage{xkeyval}
1062 \RequirePackage{etoolbox}
1063 % \end{macrocode}
1064 %
1065 % To define alias counters for theorems, load \pkgname{aliascnt}:
1066 % \begin{macrocode}
1067 \RequirePackage{aliascnt}
1068 % \end{macrocode}
1069 %
1070 % And finally, load the \textit{AMS} math and theorem (\pkgname{amsmath},
1071 % \pkgname{amsthm}) packages:
1072 % \begin{macrocode}
1073 \RequirePackage{amsmath}
1074 \RequirePackage{amsthm}
1075 % \end{macrocode}
1076 %
1077 %
1078 % \subsection{Generic Internal Stuff}
1079 %
1080 % \begin{macro}{\phfthm@internal@execattribs}
1081 %
1082 % Internal command: execute all definitions given in list of attributes. This was
1083 % copy-pasted from a similar definition in the \pkgname{phfnote} package.
1084 %
1085 % |#1| = prefix to look for attributes
1086 %
1087 % |#2| = name of what |#1| represents, to use in message in case attribute is not found
1088 %
1089 % |#3| = list of attributes
1090 %
1091 % \begin{macrocode}
1092 \def\phfthm@internal@execattribs#1#2#3{%
1093 \@for\next:=#3\do{%
1094 \ifcsname #1\next\endcsname%
1095 \csname #1\next\endcsname%
1096 \else%
1097 \PackageWarning{phfthm}{Unknown #2: '\next'. Ignoring.}
1098 \fi
1099 }
1100 }
1101 % \end{macrocode}
1102 % \end{macro}
1103 %
1104 %
1105 % \subsection{Definitions for theorem environments}
1106 %
1107 % \subsubsection{\phfverb{\phfMakeTheorem}: definition of a new theorem environment}
1108 %
1109 % First, define some key-value syntax accepted by the |\phfMakeTheorem| command.
1110 % \begin{macrocode}
1111 \define@cmdkey{phfmkthm}{counter}{}
1112 \define@boolkey{phfmkthm}{aliascounter}[true]{}
1113 \define@cmdkey{phfmkthm}{thmstyle}{}
1114 \define@boolkey{phfmkthm}{defnostar}[true]{}
1115 \define@boolkey{phfmkthm}{defstar}[true]{}
1116 \define@boolkey{phfmkthm}{proofref}[true]{}
1117 \define@cmdkey{phfmkthm}{parentcounter}{}
1118 \define@cmdkey{phfmkthm}{proofrefstyle}{}
1119 % \end{macrocode}
1120 %
1121 % \begin{macro}{\phfMakeTheorem}
1122 % Define a new theorem environment. The syntax is
1123 % |\phfMakeTheorem|\hspace{0pt}\oarg{options}\hspace{0pt}\marg{theorem
1124 % environment name}\hspace{0pt}\marg{Theorem Display Name}. For example:
1125 % |\phfMakeTheorem[counter=thmcounter]{prop}{Proposition}|
1126 % \begin{macrocode}
1127 \newcommand\phfMakeTheorem[3][]{% }
1128 % \end{macrocode}
1129 % Handle the [options]. First, ensure that the defaults are set, and then, parse the input.
1130 % \begin{macrocode}
1131 \KV@phfmkthm@aliascountertrue%
1132 \def\cmdKV@phfmkthm@counter{}%
1133 \def\cmdKV@phfmkthm@thmstyle{}%
1134 \KV@phfmkthm@defnostartrue%
1135 \KV@phfmkthm@defstartrue%
1136 \KV@phfmkthm@proofreftrue%
1137 \def\cmdKV@phfmkthm@parentcounter{}%
1138 \def\cmdKV@phfmkthm@proofrefstyle{default}%
1139 \setkeys{phfmkthm}{#1}%
1140 % \end{macrocode}
1141 %
1142 % Now, react to whatever was given in the options.
1143 %
1144 % \verbdef\tmptheifconstruct|\if\relax\detokenize{...}\relax|
1145 % Set the theorem style, if requested.\footnote{The construct
1146 % \tmptheifconstruct\space tests whether \phfverb{...} is empty: see
1147 % \url{http://tex.stackexchange.com/a/53091/32188}}
1148 % \begin{macrocode}
1149 \if\relax\detokenize\expandafter{\cmdKV@phfmkthm@thmstyle}\relax%
1150 \else%
1151 \theoremstyle{\cmdKV@phfmkthm@thmstyle}%
1152 \fi%
1153 % \end{macrocode}
1154 %
1155 % If requested, define the default, unstarred version of the theorem. Use
1156 % |\newtheorem| for that, which we make sure to call appropriately depending on
1157 % whether a separate counter is requested or not. Make sure also to define
1158 % |\...autorefname| for |\autoref|. If an alias counter is requested, create it
1159 % and pass that one to |\newtheorem|.
1160 %
1161 % At this point, we create a theorem named |phfthm@...| using |\newtheorem|
1162 % (because we still want to add calls to hooks).
1163 % \begin{macrocode}
1164 \ifKV@phfmkthm@defnostar%
1165 \if\relax\detokenize\expandafter{\cmdKV@phfmkthm@counter}\relax%
1166 % \end{macrocode}
1167 % ---in case we use a separate given counter (if \cmdoptionfmt{counter=} is
1168 % given empty or not specified). Also check if we want a parent counter
1169 % (per-section or per-chapter numbering) and take that into account:
1170 % \begin{macrocode}
1171 \if\relax\detokenize\expandafter{\cmdKV@phfmkthm@parentcounter}\relax%
1172 \edef\x{\noexpand\newtheorem{phfthm@#2}{#3}}%
1173 \else
1174 \edef\x{\noexpand\newtheorem{phfthm@#2}{#3}[\expandonce\cmdKV@phfmkthm@parentcounter]}%
1175 \fi
1176 \x
1177 \csdef{phfthm@#2autorefname}{#3}%
1178 \else%
1179 \ifKV@phfmkthm@aliascounter%
1180 % \end{macrocode}
1181 % ---in case we make a distinct alias counter, eg. for use with |\autoref|:
1182 % \begin{macrocode}
1183 \newaliascnt{#2}{\cmdKV@phfmkthm@counter}%
1184 \newtheorem{phfthm@#2}[#2]{#3}%
1185 \aliascntresetthe{#2}%
1186 \csdef{#2autorefname}{#3}%
1187 \else%
1188 % \end{macrocode}
1189 % ---in case we directly instruct |\newtheorem| to use the other counter (does
1190 % not work with |\autoref|):
1191 % \begin{macrocode}
1192 \newtheorem{phfthm@#2}[\cmdKV@phfmkthm@counter]{#3}%
1193 \fi%
1194 \fi%
1195 % \end{macrocode}
1196 %
1197 % And also define the actual theorem environment, adding calls to hooks.
1198 % \begin{macrocode}
1199 \newenvironment{#2}[1][]{%
1200 \begin{phfthm@#2}[{##1}]%
1201 \begingroup%
1202 \csname phfthm@hook@start@#2\endcsname{##1}%
1203 }{%
1204 \csname phfthm@hook@end@#2\endcsname%
1205 \endgroup%
1206 \end{phfthm@#2}%
1207 }%
1208 % \end{macrocode}
1209 % Define hooks specific to this theorem with sensible defaults. If proof-ref is
1210 % on, call the appropriate callbacks. Then, call the common hooks (see
1211 % |\phfthm@hook@startcommonnostar|, |\phfthm@hook@afterlabelcommon| and
1212 % |\phfthm@hook@endcommonnostar|, detailed in \autoref{sec:theorem-hooks}).
1213 % \begin{macrocode}
1214 \csedef{phfthm@hook@start@#2}##1{%
1215 \ifKV@phfmkthm@proofref%
1216 \expandafter\noexpand%
1217 \csname phfthm@proofrefstyle@\cmdKV@phfmkthm@proofrefstyle @setup\endcsname%
1218 \noexpand\phfthm@def@label@thmlabel{#2}%
1219 \noexpand\phfthm@proofref@impl@start%
1220 \fi%
1221 \noexpand\phfthm@hook@startcommonnostar{#2}{##1}%
1222 }%
1223 \csedef{phfthm@hook@afterlabel@#2}{%
1224 \ifKV@phfmkthm@proofref%
1225 \noexpand\phfthm@proofref@expandthmlabeltoarg%
1226 \noexpand\phfthm@proofref@impl@afterlabel%
1227 \fi%
1228 \noexpand\phfthm@hook@afterlabelcommon{#2}%
1229 }%
1230 \csedef{phfthm@hook@end@#2}{%
1231 \ifKV@phfmkthm@proofref%
1232 \noexpand\phfthm@proofref@expandthmlabeltoarg%
1233 \noexpand\phfthm@proofref@impl@end%
1234 \fi%
1235 \noexpand\phfthm@hook@endcommonnostar{#2}%
1236 }%
1237 \fi%
1238 % \end{macrocode}
1239 %
1240 %
1241 % If requested, define the starred version of the theorem. We call
1242 % |\newtheorem*| to define the base theorem environment (which we call
1243 % |phfthm@...|), after which as above we define the actual environment which
1244 % also calls the relevant hooks.
1245 % \begin{macrocode}
1246 \ifKV@phfmkthm@defstar%
1247 \newtheorem*{phfthm@#2*}{#3}%
1248 \newenvironment{#2*}[1][]{%
1249 \begin{phfthm@#2*}[##1]%
1250 \begingroup%
1251 \csname phfthm@hook@start@#2*\endcsname{##1}%
1252 }{%
1253 \csname phfthm@hook@end@#2*\endcsname%
1254 \endgroup%
1255 \end{phfthm@#2*}%
1256 }%
1257 \fi%
1258 % \end{macrocode}
1259 %
1260 % Finally, define the default hooks specific to the starred version of the
1261 % theorem (see \autoref{sec:theorem-hooks}).
1262 % \begin{macrocode}
1263 \csdef{phfthm@hook@start@#2*}##1{\phfthm@hook@startcommonstar{#2}{##1}}%
1264 \csdef{phfthm@hook@end@#2*}{\phfthm@hook@endcommonstar{#2}}%
1265 }
1266 % \end{macrocode}
1267 % \end{macro}
1268 %
1269 %
1270 % \subsubsection{Default hooks for theorems}
1271 %
1272 % \needspace{3\baselineskip}
1273 % \begin{macro}{\phfthm@hook@startcommonnostar}
1274 % \begin{macro}{\phfthm@hook@startcommonstar}
1275 % \begin{macro}{\phfthm@hook@startcommon}
1276 % Common default hooks definitions for start of the theorems.
1277 %
1278 % For all three of these hooks, we have
1279 % |#1| = theorem name, e.g. |proposition| and
1280 % |#2| = full (optional) title of proposition, if given, or empty.
1281 %
1282 % Make sure to invoke the |\label| re-definition hack only for non-starred
1283 % theorems/propositions; indeed, if no theorem label is set we don't want to
1284 % interfere with labels set to inner equations, itemizes etc. Hence, call
1285 % |\phfhtm@def@label@thmlabel| only in the ``nostar'' hook.
1286 % \begin{macrocode}
1287 \def\phfthm@hook@startcommonnostar#1#2{%
1288 \phfthm@hook@startcommon{#1}{#2}%
1289 }
1290 \def\phfthm@hook@startcommonstar#1#2{%
1291 \phfthm@hook@startcommon{#1}{#2}%
1292 }
1293 \def\phfthm@hook@startcommon#1#2{%
1294 % \end{macrocode}
1295 % Furthermore, in any case, set the |\postdisplaypenalty| to avoid an orphan
1296 % line on a new page after display equation.
1297 % \begin{macrocode}
1298 \postdisplaypenalty=10000\relax%
1299 }
1300 % \end{macrocode}
1301 % \end{macro}
1302 % \end{macro}
1303 % \end{macro}
1304 %
1305 % \begin{macro}{\phfthm@hook@afterlabelcommon}
1306 % \begin{macro}{\phfthm@hook@endcommonnostar}
1307 % \begin{macro}{\phfthm@hook@endcommonstar}
1308 % \begin{macro}{\phfthm@hook@endcommon}
1309 % Further hooks, for after the theorem main |\label| command
1310 % (|\phfthm@hook@afterlabelcommon|) and for the end of the theorem.
1311 % \begin{macrocode}
1312 \def\phfthm@hook@afterlabelcommon#1{}
1313 \def\phfthm@hook@endcommonnostar#1{\phfthm@hook@endcommon{#1}}
1314 \def\phfthm@hook@endcommonstar#1{\phfthm@hook@endcommon{#1}}
1315 \def\phfthm@hook@endcommon#1{}
1316 % \end{macrocode}
1317 % \end{macro}
1318 % \end{macro}
1319 % \end{macro}
1320 % \end{macro}
1321 %
1322 % \subsubsection{Proof-ref mechanism (on the theorem side)}
1323 %
1324 % These macros enable the proof-ref mechanism
1325 % (\autoref{sec:proof-ref-mechanism}). The theorem's label is stored upon
1326 % calling |\label|, because we (locally) hack into the definition of |\label|.
1327 % (After the first usage of |\label| its meaning is restored.)
1328 % \begin{macro}{\phfthm@def@label@thmlabel}
1329 % Main macro to invoke at the beginning of the theorem environment, so that
1330 % the theorem label is stored in a local macro once |\label| is invoked. This
1331 % hacks the |\label| macro locally. Here, |#1| = the theorem environment
1332 % name, e.g.\@ |proposition|.
1333 % \begin{macrocode}
1334 \def\phfthm@def@label@thmlabel#1{%
1335 \ifdefined\phfthm@old@label
1336 \PackageWarning{phfthm}{Internal inconsistency: \string\phfthm@def@label@thmlabel
1337 called twice for the same theorem environment!}
1338 \else
1339 \let\phfthm@old@label\label%
1340 \edef\label{\noexpand\phfthm@thmlabel{#1}}%
1341 \fi
1342 }
1343 % \end{macrocode}
1344 % \end{macro}
1345 %
1346 % \begin{macro}{\phfthm@thmlabel}
1347 % The first call to |\label| within the theorem redirects to the macro
1348 % |\phfthm@thmlabel|. (Applies to theorem environments for which
1349 % |\phfthm@def@label@thmlabel| was called, which is the default).
1350 %
1351 % Here |#1| = theorem environment name, e.g.\@ |proposition|; and |#2| = the
1352 % label value (argument to the |\label| macro).
1353 % \begin{macrocode}
1354 \def\phfthm@thmlabel#1#2{%
1355 % \end{macrocode}
1356 % First, store the label value into a macro called |\phfthm@val@thmlabel|.
1357 % \begin{macrocode}
1358 \def\phfthm@val@thmlabel{#2}%
1359 % \end{macrocode}
1360 % Then, call the original |\label| macro to do what \LaTeX\space would normally
1361 % do for a |\label{|\ldots|}| call.
1362 % \begin{macrocode}
1363 \phfthm@old@label{#2}%
1364 % \end{macrocode}
1365 % Restore the old |\label| definition, in case there are other items in the
1366 % theorem environment such as equations, itemizes etc.\@ which may themselves
1367 % have |\label|'s.
1368 % \begin{macrocode}
1369 \let\label\phfthm@old@label%
1370 % \end{macrocode}
1371 % Invoke the |\phfthm@hook@afterlabel@thmname| hook for this theorem
1372 % environment.
1373 % \begin{macrocode}
1374 \csname phfthm@hook@afterlabel@#1\endcsname%
1375 % \end{macrocode}
1376 % Finally, ignore any spaces following the |\label| command. (Maybe we should
1377 % have done something with |\@bsphack| and |\@esphack| but oh well\ldots
1378 % \begin{macrocode}
1379 \ignorespaces%
1380 }
1381 % \end{macrocode}
1382 % \end{macro}
1383 %
1384 %
1385 % \subsection{Definitions for proof environments}
1386 %
1387 % Improved, smarter |proof| environments.
1388 %
1389 % \begin{macro}{\phfthm@old@proof}
1390 % \begin{macro}{\endphfthm@old@proof}
1391 % Save old |proof| environment provided by \pkgname{amsthm}.
1392 % \begin{macrocode}
1393 \let\phfthm@old@proof\proof
1394 \let\endphfthm@old@proof\endproof
1395 % \end{macrocode}
1396 % \end{macro}
1397 % \end{macro}
1398 %
1399 % \begin{macro}{\proofname}
1400 % And provide a default name for proofs (this should normally already be
1401 % provided by \pkgname{amsthm}).
1402 % \begin{macrocode}
1403 \providecommand\proofname{Proof}
1404 % \end{macrocode}
1405 % \end{macro}
1406 %
1407 % \begin{macro}{\proofofname}
1408 % Default text to display when we want to say e.g.\@ ``Proof of Theorem 3.''
1409 % \begin{macrocode}
1410 \def\proofofname#1{\proofname\space of #1}
1411 % \end{macrocode}
1412 % \end{macro}
1413 %
1414 % The default counter for proofs. The value of this counter is typically not
1415 % displayed, we just use it to pin down anchors for labels for cross references.
1416 % \begin{macrocode}
1417 \newcounter{phfthmproofcnt}
1418 % \end{macrocode}
1419 %
1420 % Utility: to see if an argument was specified (possibly empty) to the proof
1421 % environment.
1422 % \begin{macrocode}
1423 \def\phfthm@NOPROOFARG{}
1424 \def\phfthm@test@NOPROOFARG{\phfthm@NOPROOFARG}
1425 % \end{macrocode}
1426 %
1427 % \subsubsection{Define a proof environment: \phfverb{\phfMakeProofEnv}}
1428 %
1429 % Declare some key-value options accepted by |\phfMakeProofEnv|. See
1430 % \autoref{sec:mk-proof-env} for the documentation of these options.
1431 % \begin{macrocode}
1432 \define@cmdkey{phfmkprf}{displayenv}{}
1433 \define@cmdkey{phfmkprf}{defaultproofname}{}
1434 \define@boolkey{phfmkprf}{override}[true]{}
1435 \define@cmdkey{phfmkprf}{internalcounter}{}
1436 \define@cmdkey{phfmkprf}{proofofname}{}
1437 \define@boolkey{phfmkprf}{parselabel}[true]{}
1438 \define@cmdkey{phfmkprf}{parselabelcmd}{}
1439 % \end{macrocode}
1440 %
1441 % \begin{macro}{\phfMakeProofEnv}
1442 % Make a proof environment. Syntax:
1443 % |\phfMakeProofEnv|\hspace{0pt}\oarg{options}\hspace{0pt}\marg{proof
1444 % environment name}.
1445 % \begin{macrocode}
1446 \newcommand\phfMakeProofEnv[2][]{%}
1447 % \end{macrocode}
1448 %
1449 % Parse the key-value options. First, make sure that all the defaults are set,
1450 % then parse the options.
1451 % \begin{macrocode}
1452 \KV@phfmkprf@overridefalse%
1453 \def\cmdKV@phfmkprf@displayenv{*}%
1454 \def\cmdKV@phfmkprf@defaultproofname{\proofname}%
1455 \def\cmdKV@phfmkprf@internalcounter{phfthmproofcnt}%
1456 \def\cmdKV@phfmkprf@proofofname{\proofofname}%
1457 \KV@phfmkprf@parselabeltrue
1458 \def\cmdKV@phfmkprf@parselabelcmd{\phfthm@proof@parselabel}%
1459 \setkeys{phfmkprf}{#1}%
1460 % \end{macrocode}
1461 %
1462 % The meaning of the options are detailed in \autoref{sec:mk-proof-env}.
1463 %
1464 % The general idea here is first to pre-process all the options, and save all
1465 % the useful information in macros named
1466 % |\phfthm@prfenv@<proof-environment-name>@val@<something>|. Then, we can define
1467 % the begin/end environment macros which will recall the saved information.
1468 %
1469 % Take care of the display environment to use. Recall that if |displayenv=*|,
1470 % we use our own default; if |displayenv=| (empty), there is no display
1471 % environment. Here, we set
1472 % |\phfthm@prfenv@<proof-environment-name>@val@displayenv| to the name of the
1473 % environment to use (possibly empty), for later reference.
1474 % \begin{macrocode}
1475 \def\phfmkprf@tmp@star{*}%
1476 \ifx\cmdKV@phfmkprf@displayenv\phfmkprf@tmp@star\relax%
1477 \def\cmdKV@phfmkprf@displayenv{phfthm@proof@defaultdisplayenv}%
1478 \fi
1479 \cslet{phfthm@prfenv@#2@val@displayenv}\cmdKV@phfmkprf@displayenv%
1480 % \end{macrocode}
1481 %
1482 % Process the default proof name. If none is given, use |\proofname| and pass
1483 % no option to the underlying display environment whenever the proof environment
1484 % is called with no option. Here, we set
1485 % |\phfthm@prfenv@<proof-environment-name>@val@defaultproofnameargs| and
1486 % |\phfthm@prfenv@<proof-environment-name>@val@setdefaultprooftitle|; the former
1487 % is the tokens to put in front of the proof environment invocation in case no
1488 % explicit proof title is given to the proof environment while the latter
1489 % contains the command to set |\phfthm@val@prooftitle| to the default proof
1490 % name.
1491 % \begin{macrocode}
1492 \if\relax\detokenize\expandafter{\cmdKV@phfmkprf@defaultproofname}\relax%
1493 \csdef{phfthm@prfenv@#2@val@defaultproofnameargs}{}%
1494 \csdef{phfthm@prfenv@#2@val@setdefaultprooftitle}{%
1495 \def\phfthm@val@prooftitle{\proofname}}%
1496 \else
1497 \csedef{phfthm@prfenv@#2@val@defaultproofnameargs}{%
1498 [\expandonce{\cmdKV@phfmkprf@defaultproofname}]}%
1499 \csedef{phfthm@prfenv@#2@val@setdefaultprooftitle}{%
1500 \noexpand\def\noexpand\phfthm@val@prooftitle{%
1501 \expandonce{\cmdKV@phfmkprf@defaultproofname}}}%
1502 \fi
1503 \csedef{phfthm@prfenv@#2@val@parselabelandmkdisplayargs}##1{%
1504 \ifKV@phfmkprf@parselabel
1505 \expandonce\cmdKV@phfmkprf@parselabelcmd{##1}%
1506 \else
1507 \noexpand\phfthm@proof@noparselabel{##1}%
1508 \fi
1509 \noexpand\if\noexpand\relax\noexpand\detokenize%
1510 \noexpand\expandafter{\noexpand\phfthm@val@prooftitle}\noexpand\relax
1511 \noexpand\def\noexpand\phfthm@val@displayargs{}
1512 \noexpand\else
1513 \noexpand\def\noexpand\phfthm@val@displayargs{[{%
1514 \expandafter\noexpand\csname phfthm@prfenv@#2@val@proofofname\endcsname
1515 {\noexpand\phfthm@val@prooftitle}%
1516 }]}%
1517 \noexpand\fi
1518 }
1519 % \end{macrocode}
1520 %
1521 % Store the macro which creates the ``Proof of \ldots'' text (|proofofname|
1522 % option).
1523 % \begin{macrocode}
1524 \cslet{phfthm@prfenv@#2@val@proofofname}\cmdKV@phfmkprf@proofofname%
1525 % \end{macrocode}
1526 %
1527 % Create the macro which will take care of pinning down the label for the
1528 % proof-ref (see \autoref{sec:proof-ref-mechanism}). This macro first ref-steps
1529 % the internal counter and then pins down a label, if appropriate.
1530 % \begin{macrocode}
1531 \csdef{phfthm@prfenv@#2@val@pinproofanchor}{%
1532 \csname phfthm@prfenv@#2@val@refstepinternalcounter\endcsname%
1533 \if\relax\detokenize\expandafter{\phfthm@val@proofoflabel}\relax\else%
1534 \edef\phfthm@tmp@larg{{proof:\phfthm@val@proofoflabel}}%
1535 \expandafter\label\phfthm@tmp@larg%
1536 \fi
1537 }%
1538 %
1539 % \end{macrocode}
1540 %
1541 % The command to ref-step the internal proof counter. Use the value of the
1542 % \cmdoptionfmt{internalcounter} command option.
1543 % \begin{macrocode}
1544 \csedef{phfthm@prfenv@#2@val@refstepinternalcounter}{%
1545 \noexpand\refstepcounter{\cmdKV@phfmkprf@internalcounter}}%
1546 % \end{macrocode}
1547 %
1548 % Make macros |\phfthm@prfenv@<proof-environment-name>@val@displayenvbegincmd|
1549 % and |\phfthm@prfenv@<proof-environment-name>@val@displayenvendcmd|, which
1550 % essentially expand to |\begin{<the-display-env>}| and
1551 % |\end{<the-display-env>}| for the display environment given in the option
1552 % \cmdoptionfmt{displayenv}.
1553 % \begin{macrocode}
1554 \if\relax\detokenize\expandafter{\cmdKV@phfmkprf@displayenv}\relax%
1555 \csdef{phfthm@prfenv@#2@val@displayenvbegincmd}##1{}%
1556 \csdef{phfthm@prfenv@#2@val@displayenvendcmd}##1{}%
1557 \else
1558 \csedef{phfthm@prfenv@#2@val@displayenvbegincmd}##1{%
1559 \noexpand\begin{\csname phfthm@prfenv@#2@val@displayenv\endcsname}##1}%
1560 \csedef{phfthm@prfenv@#2@val@displayenvendcmd}##1{%
1561 \noexpand\end{\csname phfthm@prfenv@#2@val@displayenv\endcsname}##1}%
1562 \fi
1563 % \end{macrocode}
1564 %
1565 % See if we need to call |\newenvironment| or |\renewenvironment|, depending on
1566 % the value of the \cmdoptionfmt{override} option.
1567 % \begin{macrocode}
1568 \def\phfthm@tmp@defcmd{\newenvironment}%
1569 \ifKV@phfmkprf@override\def\phfthm@tmp@defcmd{\renewenvironment}\fi%
1570 % \end{macrocode}
1571 %
1572 % Finally, (re-)define the environment. The default value of the optional
1573 % argument is the token |\phfthm@NOPROOFARG|, which indicates that no argument
1574 % was provided.
1575 %
1576 % Start by storing the value of the argument into a macro, and then call the
1577 % ``start'' hook (see proof hooks in \autoref{sec:proof-hooks}).
1578 % \begin{macrocode}
1579 \phfthm@tmp@defcmd{#2}[1][\phfthm@NOPROOFARG]{%
1580 \def\phfthm@val@proofarg{##1}%
1581 \csname phfthm@hookproof@#2@start\endcsname%
1582 % \end{macrocode}
1583 %
1584 % First, parse the optional argument into proof label (maybe) and proof title.
1585 % If no optional argument was given, don't give any argument to the underlying
1586 % display environment. If an empty argument was given, set some defaults;
1587 % otherwise, use the necessary command to potentially parse the label and create
1588 % the proper arguments for the underlying display environment.
1589 % \begin{macrocode}
1590 \ifx\phfthm@val@proofarg\phfthm@test@NOPROOFARG\relax%
1591 \def\phfthm@val@proofoflabel{}%
1592 \csname phfthm@prfenv@#2@val@setdefaultprooftitle\endcsname%
1593 \letcs\phfthm@val@displayargs{phfthm@prfenv@#2@val@defaultproofnameargs}%
1594 \else%
1595 \if\relax\detokenize{##1}\relax%
1596 \def\phfthm@val@proofoflabel{}%
1597 \csname phfthm@prfenv@#2@val@setdefaultprooftitle\endcsname%
1598 \def\phfthm@val@displayargs{[{%
1599 \csname phfthm@prfenv@#2@val@proofofname\endcsname
1600 {\phfthm@val@prooftitle}%
1601 }]}%
1602 \else
1603 \csname phfthm@prfenv@#2@val@parselabelandmkdisplayargs\endcsname{##1}%
1604 \fi
1605 \fi%
1606 % \end{macrocode}
1607 %
1608 % Define the |\phfPinProofAnchor| command (locally) in case the
1609 % display formatting environment takes care of where to place the anchor already.
1610 % \begin{macrocode}
1611 \def\phfPinProofAnchor{%
1612 \csname phfthm@prfenv@#2@val@pinproofanchor\endcsname%
1613 \global\let\phfPinProofAnchor\relax}%
1614 % \end{macrocode}
1615 % [Also provide the obsolete |\phfthmPinProofAnchor| which I previously had in
1616 % older versions of this package:]
1617 % \begin{macrocode}
1618 \def\phfthmPinProofAnchor{\phfPinProofAnchor}%
1619 % \end{macrocode}
1620 %
1621 % Start the proof's display environment. Don't be fooled here by the curly
1622 % braces after |\x|, it only protects the argument to the
1623 % |\phfthm@prfenv@#2@val@displayenvbegincmd| command itself: the
1624 % |\phfthm@val@displayargs| are still just tokens which will be expanded in
1625 % front of the |\beg||in{<proof-display-env>}| command.
1626 % \begin{macrocode}
1627 \def\x{\csname phfthm@prfenv@#2@val@displayenvbegincmd\endcsname}%
1628 \expandafter\x\expandafter{\phfthm@val@displayargs}%
1629 % \end{macrocode}
1630 % And call the corresponding hook:
1631 % \begin{macrocode}
1632 \csname phfthm@hookproof@#2@startafterdisplay\endcsname%
1633 % \end{macrocode}
1634 % If required, pin anchor after the proof-display-environment.
1635 % (|\phfPinProofAnchor| auto-destructs after first use, so it's safe to
1636 % potentially call it a second time here). Then, call the corresponding hook.
1637 % \begin{macrocode}
1638 \phfPinProofAnchor%
1639 \expandafter\noexpand\csname phfthm@hookproof@#2@startlast\endcsname%
1640 }%
1641 % \end{macrocode}
1642 %
1643 % Now, the definitions for the ``end'' part of the environment. Just call the
1644 % relevant hooks and close the display environment.
1645 % \begin{macrocode}
1646 {%
1647 \expandafter\noexpand\csname phfthm@hookproof@#2@end\endcsname%
1648 \csname phfthm@prfenv@#2@val@displayenvendcmd\endcsname
1649 \expandafter\noexpand\csname phfthm@hookproof@#2@final\endcsname%
1650 }%
1651 % \end{macrocode}
1652 %
1653 % Finally, define the default values of the proof-environment-specific hooks.
1654 % These just call the corresponding global hooks (see \autoref{sec:proof-hooks}).
1655 % \begin{macrocode}
1656 \csdef{phfthm@hookproof@#2@start}{\phfthm@hookproof@startcommon{#2}}%
1657 \csdef{phfthm@hookproof@#2@startafterdisplay}{%
1658 \phfthm@hookproof@startafterdisplaycommon{#2}}%
1659 \csdef{phfthm@hookproof@#2@startlast}{\phfthm@hookproof@startlastcommon{#2}}%
1660 \csdef{phfthm@hookproof@#2@end}{\phfthm@hookproof@endcommon{#2}}%
1661 \csdef{phfthm@hookproof@#2@final}{\phfthm@hookproof@finalcommon{#2}}%
1662 }
1663 % \end{macrocode}
1664 % \end{macro}
1665 %
1666 %
1667 % \subsubsection{Common hooks for proofs}
1668 %
1669 % The hooks are documented in \autoref{sec:proof-hooks}.
1670 % \begin{macrocode}
1671 \def\phfthm@hookproof@startcommon#1{}
1672 \def\phfthm@hookproof@startafterdisplaycommon#1{}
1673 \def\phfthm@hookproof@startlastcommon#1{}
1674 \def\phfthm@hookproof@endcommon#1{}
1675 \def\phfthm@hookproof@finalcommon#1{}
1676 % \end{macrocode}
1677 %
1678 %
1679 % \subsubsection{Default display environment for proofs}
1680 %
1681 % \begin{environment}{phfthm@proof@defaultdisplayenv}
1682 % Provide an environment which displays a proof in a similar fashion as
1683 % \emph{AMS}', but with some small additional features.
1684 % \begin{macrocode}
1685 \newenvironment{phfthm@proof@defaultdisplayenv}[1][\proofname]{%
1686 \par
1687 \pushQED{\qed}%
1688 \normalfont \topsep6\p@\@plus6\p@\relax
1689 \trivlist\item\relax
1690 \phfPinProofAnchor
1691 \phfthm@ProofTitleFmt{#1}%
1692 \phfthm@ProofTitleHspace
1693 \ignorespaces
1694 }{%
1695 \popQED\endtrivlist\@endpefalse
1696 }
1697 % \end{macrocode}
1698 % \end{environment}
1699 %
1700 % \begin{macro}{\phfthm@ProofTitleFmt}
1701 % \begin{macro}{\phfthm@ProofTitleHspace}
1702 % These macros may be overridden to change the proof title appearance.
1703 % \begin{macrocode}
1704 \def\phfthm@ProofTitleFmt#1{%
1705 {\itshape #1.}%
1706 }
1707 \def\phfthm@ProofTitleHspace{%
1708 \hspace{1.5ex plus 0.5ex minus 0.2ex}%
1709 }
1710 % \end{macrocode}
1711 % \end{macro}
1712 % \end{macro}
1713 %
1714 % \subsubsection{Parsing the proof argument}
1715 %
1716 % These macros parse the argument of the proof environment to see if it is of
1717 % the form |*<some-label>| (see \autoref{sec:proof-ref-mechanism}).
1718 %
1719 % \begin{macro}{\phfthm@proof@parselabel}
1720 % Call |\phfthm@proof@parselabel|\marg{proof environment argument} to parse
1721 % the argument string. This macro will set |\phfthm@val@proofoflabel| and
1722 % |\phfthm@val@prooftitle| to appropriate values (respectively, the label name
1723 % of the corresponding theorem and a representative title such as ``Theorem
1724 % 6'').
1725 % \begin{macrocode}
1726 \def\phfthm@proof@parselabel#1{%
1727 \phfthm@proof@parselabel@maybelabel#1\phfthm@proof@parselabel@END%
1728 }
1729 % \end{macrocode}
1730 % If the argument is |[*thm-label]| we want ``Proof of \meta{ref to
1731 % thm-label}.''. If the argument is |[**thm-label]| we want ``Proof.'' but
1732 % we're informing the proofref-system that this is the proof of \meta{thm-label}
1733 % (e.g., to avoid undefined references to proofs). Otherwise if we get %
1734 % |[Some Custom Theorem]| then we want ``Proof of Some Custom Theorem.''.
1735 % \begin{macrocode}
1736 \def\phfthm@proof@parselabel@maybelabel{%
1737 \@ifnextchar*\phfthm@proof@parselabel@label\phfthm@proof@parselabel@title%
1738 }
1739 \def\phfthm@proof@parselabel@label*{%
1740 \@ifnextchar*\phfthm@proof@parselabel@labelsilent\phfthm@proof@parselabel@labelnormal%
1741 }
1742 \def\phfthm@proof@parselabel@labelsilent*#1\phfthm@proof@parselabel@END{%
1743 % \end{macrocode}
1744 % The use of |\detokenize| here is a trick to make sure that all chars in the
1745 % label text have a non-active category (e.g.\@ we would have problems, e.g., if
1746 % in the label ``|thm:gauss|'' the ``|:|'' is an active char---such as in French):
1747 % \begin{macrocode}
1748 \edef\phfthm@val@proofoflabel{\detokenize{#1}}%
1749 \def\phfthm@val@prooftitle{}%
1750 }
1751 \def\phfthm@proof@parselabel@labelnormal#1\phfthm@proof@parselabel@END{%
1752 \edef\phfthm@val@proofoflabel{\detokenize{#1}}%
1753 \def\phfthm@val@prooftitle{\phfthm@autoref{#1}}%
1754 }
1755 \def\phfthm@proof@parselabel@title#1\phfthm@proof@parselabel@END{%
1756 \def\phfthm@val@proofoflabel{}%
1757 \def\phfthm@val@prooftitle{#1}%
1758 }
1759 % \end{macrocode}
1760 % \end{macro}
1761 % \begin{macro}{\phfthm@proof@noparselabel}
1762 % Enjoys the same syntax as |\phfthm@proof@parselabel|, i.e., it is a drop-in
1763 % replacement for the latter, except that it invariably sets
1764 % |\phfhtm@val@proofoflabel| to an empty value and |\phfthm@val@prooftitle| to
1765 % the argument itself. You could use this as a \cmdoptionfmt{parselabelcmd}
1766 % macro if you didn't want to parse the label.
1767 % \begin{macrocode}
1768 \def\phfthm@proof@noparselabel#1{%
1769 \def\phfthm@val@proofoflabel{}%
1770 \def\phfthm@val@prooftitle{#1}%
1771 }
1772 % \end{macrocode}
1773 % \end{macro}
1774 %
1775 %
1776 % In order to look up what we are a proof of, we use |\autoref| provided by the
1777 % \pkgname{hyperref} package. Crucially, it is NOT the job of \pkgname{phfthm}
1778 % to load this package, and we should only use them if they are available (we
1779 % don't want to depend on it). If it is not available, then we fall back to the
1780 % regular |\ref| command.
1781 % \begin{macrocode}
1782 \def\phfthm@autoref{\ref}
1783 \AtBeginDocument{%
1784 \@ifpackageloaded{hyperref}{\def\phfthm@autoref{\autoref}}{}%
1785 }
1786 % \end{macrocode}
1787 %
1788 %
1789 % \subsection{Implementation of the proof-ref machinery}
1790 %
1791 % \subsubsection{Small general stuff}
1792 %
1793 % \begin{macro}{\proofonname}
1794 % The macro |\proofonname| displays ``Proof on \ldots.'' Here, |#2| is the
1795 % full page reference and |#1| is the label name of the referenced theorem.
1796 % \begin{macrocode}
1797 \providecommand\proofonname[2]{Proof on #2.}
1798 % \end{macrocode}
1799 % \end{macro}
1800 %
1801 % \begin{macro}{\proofrefsize}
1802 % Format the proof reference ``Proof on page \ldots''. This macro is meant to
1803 % set the font size (or other font properties), but it may also be defined to
1804 % take one argument, the proof reference text.
1805 % \begin{macrocode}
1806 \def\proofrefsize{\footnotesize}
1807 % \end{macrocode}
1808 % \end{macro}
1809 %
1810 %
1811 % \begin{macro}{\noproofref}
1812 % Use |\noproofref| inside a theorem to signify that no proof reference should
1813 % be attempted.
1814 %
1815 % The implementation just defines |\phfthm@val@noproofref|. If this macro is
1816 % defined, then no proof ref should be generated for the current thmlabel.
1817 % Also, restore |\label| to its original definition in case it was overridden.
1818 % \begin{macrocode}
1819 \def\noproofref{%
1820 \def\phfthm@val@noproofref{1}%
1821 \ifdefined\phfthm@old@label \let\label\phfthm@old@label \fi%
1822 }
1823 % \end{macrocode}
1824 % \end{macro}
1825 %
1826 %
1827 % \begin{macro}{\phfthm@proofref@warnnolabel}
1828 % Produce a warning that no label was provided in order to infer the proof
1829 % reference.
1830 % \begin{macrocode}
1831 \def\phfthm@proofref@warnnolabel{%
1832 \PackageWarning{phfthm}{No label provided for proof reference!}%
1833 }
1834 % \end{macrocode}
1835 % \end{macro}
1836 %
1837 % \begin{macro}{\phfthm@proofref@expandthmlabeltoarg}
1838 % Utility to expand the value of |\phfthm@val@thmlabel| as an argument to a
1839 % callback command. |#1| = the macro to relay the call to.
1840 % \begin{macrocode}
1841 \def\phfthm@proofref@expandthmlabeltoarg#1{%
1842 % \end{macrocode}
1843 %
1844 % First, check if the proof-ref mechanism was explicitly temporarily disabled,
1845 % and do nothing if that is the case.
1846 % \begin{macrocode}
1847 \ifdefined\phfthm@val@noproofref\relax%
1848 \else%
1849 % \end{macrocode}
1850 %
1851 % Then make sure |\phfthm@val@thmlabel| is defined (maybe empty), and then
1852 % either call the callback macro |#1| with the value of |\phfthm@val@thmlabel|
1853 % as argument, or generate a warning if that value is empty.
1854 % \begin{macrocode}
1855 \providecommand\phfthm@val@thmlabel{}%
1856 \edef\phfthm@tmpa{{\phfthm@val@thmlabel}}%
1857 \expandafter\notblank\phfthm@tmpa{%
1858 \expandafter#1\phfthm@tmpa%
1859 }{%
1860 \phfthm@proofref@warnnolabel% no label provided
1861 }%
1862 \fi%
1863 }
1864 % \end{macrocode}
1865 % \end{macro}
1866 %
1867 %
1868 % \subsubsection{Utilities for interacting with \phfverb{\autoref} labels}
1869 %
1870 % In this context, we also need some generic utilities for interacting with
1871 % |\autoref| labels.
1872 %
1873 % \begin{macro}{\phfthm@autorefnameof}
1874 % The macro |\phfthm@autorefnameof| extracts the name of the counter which
1875 % generated this reference (e.g.\@ ``section'' or ``theorem'').
1876 % \begin{macrocode}
1877 \def\phfthm@autorefnameof#1{%
1878 % \end{macrocode}
1879 %
1880 % Extract the counter part of the reference |section.NN|, which is 4th element in the
1881 % |\r@label| macro. (Code extracted from |hyperref.sty|.)
1882 % \begin{macrocode}
1883 \expandafter\ifx\csname r@#1\endcsname\relax%
1884 \textbf{??}%
1885 \else%
1886 \expandafter\expandafter\expandafter\phfthm@HyPsd@autorefname%
1887 \csname r@#1\endcsname{}{}{}{}\@nil%
1888 \fi%
1889 }
1890 \def\phfthm@HyPsd@autorefname#1#2#3#4#5\@nil{%
1891 \ifx\\#4\\%
1892 \else%
1893 \phfthm@HyPsd@@autorefname#4.\@nil%
1894 \fi%
1895 }
1896 \def\phfthm@HyPsd@@autorefname#1.#2\@nil{%
1897 \ltx@IfUndefined{#1autorefname}{%
1898 \ltx@IfUndefined{#1name}{%
1899 }{%
1900 \csname#1name\endcsname%
1901 }%
1902 }{%
1903 \csname#1autorefname\endcsname%
1904 }%
1905 }
1906 % \end{macrocode}
1907 % \end{macro}
1908 %
1909 % \begin{macro}{\phfthm@min@pageref}
1910 % A minimal pageref macro, which just extracts the page number on which the
1911 % given label is located.
1912 %
1913 % The dark magic going on here is beyond me. The code was copied from
1914 % |hyperref.sty|, in ``|\def\HyPsd@@@pageref...|'' and seems to work.
1915 %
1916 % \begin{macrocode}
1917 \def\phfthm@min@pageref#1{%
1918 \ifcsname r@#1\endcsname%
1919 \expandafter\expandafter\expandafter\expandafter
1920 \expandafter\expandafter\expandafter\@car
1921 \expandafter\expandafter\expandafter\@gobble
1922 \csname r@#1\endcsname{}\@nil
1923 \else%
1924 0%
1925 \fi%
1926 }
1927 % \end{macrocode}
1928 % \end{macro}
1929 %
1930 %
1931 % \subsubsection{Default proof-ref style, with basic machinery}
1932 % \label{sec:impl-default-proof-ref-style}
1933 %
1934 % Now we define the relevant callbacks for the default style. See documentation
1935 % in \autoref{sec:proof-ref-customize-appearance}. Recall a proof-ref style
1936 % just needs to define |\phfthm@proofrefstyle@<stylename>@setup|, which in turn
1937 % should just define the callbacks |\phfthm@proofref@impl@start|,
1938 % |\phfthm@proofref@impl@afterlabel| and |\phfthm@proofref@impl@end|. For our
1939 % default style, these callbacks further call other callbacks of the form
1940 % |\phfthm@proofref@impl@...|, such that these definitions can be re-used to
1941 % create new styles. The main proof-ref generation routine is
1942 % |\phfthm@proofrefstyle@default@main|, which can be used for either the
1943 % |...@afterlabel| or the |...@end| callback.
1944 %
1945 % \begin{macro}{\phfthm@proofrefstyle@default@fmt}
1946 % Format and display the proof reference. |#1| = the theorem's label
1947 % (e.g. |prop:1|); |#2| = the full reference (e.g. ``page XYZ'').
1948 %
1949 % This macro is the default value of the callback |\phfthm@proofref@impl@fmt|,
1950 % which is called by the default style itself.
1951 %
1952 % Use correct spacing for right-aligning the reference.\footnote{Thanks
1953 % \url{http://tex.stackexchange.com/a/43239/32188}!} If there is room on the
1954 % current line, just right-align the proof-ref text; if not, add it on a
1955 % separate line. [We can achieve this with the sequences |\hfil\null\hfil|:
1956 % if there is space, it all fits on the same line, if not, the line breaks at
1957 % the |\null| point.]
1958 % \begin{macrocode}
1959 \def\phfthm@proofrefstyle@default@fmt#1#2{%
1960 {\parfillskip=0pt\relax%
1961 \hfil\null\hfil\null\hfil%
1962 \hbox{\proofrefsize{(\proofonname{#1}{#2})}}\par}%
1963 }
1964 % \end{macrocode}
1965 % \end{macro}
1966 %
1967 %
1968 % \begin{macro}{\phfthm@proofrefstyle@default@fmtfarback}
1969 % \begin{macro}{\phfthm@proofrefstyle@default@fmtfarahead}
1970 % \begin{macro}{\phfthm@proofrefstyle@default@fmtcloseby}
1971 % These macros are the default values of the callbacks
1972 % |\phfthm@proofref@impl@fmtfarback|, |\phfthm@proofref@impl@fmtfarahead|, and
1973 % |\phfthm@proofref@impl@fmtcloseby|, which are called by the default style
1974 % itself. These callbacks define how to format and (possibly not) display the
1975 % proof reference depending on whether the proof is ``far behind'' (several
1976 % pages back), ``far ahead'' (several pages ahead) or ``close by'' (neither
1977 % far back nor far ahead), as defined by |\phfProofrefPageBackTolerance|
1978 % and |\phfProofrefPageAheadTolerance|.
1979 % \begin{macrocode}
1980 \def\phfthm@proofrefstyle@default@fmtfarback#1#2{%
1981 \phfthm@proofref@impl@fmt{#1}{#2}}
1982 \def\phfthm@proofrefstyle@default@fmtfarahead#1#2{%
1983 \phfthm@proofref@impl@fmt{#1}{#2}}
1984 \def\phfthm@proofrefstyle@default@fmtcloseby#1#2{}
1985 % \end{macrocode}
1986 % \end{macro}
1987 % \end{macro}
1988 % \end{macro}
1989 %
1990 % \begin{macro}{\phfProofrefPageBackTolerance}
1991 % \begin{macro}{\phfProofrefPageAheadTolerance}
1992 % The macros |\phfProofrefPageBackTolerance| and
1993 % |\phfProofrefPageAheadTolerance| define how many pages back or ahead the
1994 % proof should be in order to consider it ``far back'' or ``far ahead.''
1995 %
1996 % Either value may be set to |-1| to force the proof to be considered ``far
1997 % back'' or ``far ahead.''
1998 % \begin{macrocode}
1999 \newcommand\phfProofrefPageBackTolerance{1}
2000 \newcommand\phfProofrefPageAheadTolerance{1}
2001 % \end{macrocode}
2002 % \end{macro}
2003 % \end{macro}
2004 %
2005 % Define the internal counter which allows to check on which page we are at the
2006 % place of the proof reference. This is used by
2007 % |\phfthm@proofrefstyle@default@main|.
2008 % \begin{macrocode}
2009 \newcounter{phfthmInternalProofrefCounter}
2010 % \end{macrocode}
2011 %
2012 % \begin{macro}{\phfthm@proofrefstyle@default@main}
2013 % The main proof-ref generation routine. The argument |#1| is the current
2014 % label of the theorem; the referenced label is |proof:#1|.
2015 % \begin{macrocode}
2016 \def\phfthm@proofrefstyle@default@main#1{%
2017 % \end{macrocode}
2018 %
2019 % Check to see if the proof is far away ahead or back (as defined by the
2020 % tolerance macros above). Depending on each case, call the corresponding
2021 % callbacks.{\makeatletter\footnote{See \url{http://tex.stackexchange.com/a/2526} to test
2022 % whether ref is on same page. Note that was problematic, probably due to
2023 % hyperref. I needed to use my own \phfverb{\phfthm@min@pageref}
2024 % without any hyper linking mechanism in place.}}
2025 %
2026 % \begin{macrocode}
2027 \refstepcounter{phfthmInternalProofrefCounter}%
2028 \label{internalproofref\thephfthmInternalProofrefCounter}%
2029 \edef\phfthm@proofref@tmp@proofpage{\phfthm@min@pageref{proof:#1}}%
2030 \edef\phfthm@proofref@tmp@thispage{%
2031 \phfthm@min@pageref{internalproofref\thephfthmInternalProofrefCounter}}%
2032 \edef\phfthm@proofref@tmp@pagediff{%
2033 \the\numexpr\phfthm@proofref@tmp@proofpage-\phfthm@proofref@tmp@thispage\relax}%
2034 % \end{macrocode}
2035 %
2036 % If the proof is ``far back,'' call the corresponding callback.
2037 % \begin{macrocode}
2038 \ifnum\numexpr\phfthm@proofref@tmp@pagediff\relax%
2039 <\numexpr-\phfProofrefPageBackTolerance\relax%
2040 \phfthm@proofref@impl@fmtfarback{#1}{\autopageref{proof:#1}}%
2041 \else%
2042 % \end{macrocode}
2043 %
2044 % If the proof is ``far ahead,'' call the corresponding callback.
2045 % \begin{macrocode}
2046 \ifnum\numexpr\phfthm@proofref@tmp@pagediff\relax%
2047 >\numexpr\phfProofrefPageAheadTolerance\relax%
2048 \phfthm@proofref@impl@fmtfarahead{#1}{\autopageref{proof:#1}}%
2049 % \end{macrocode}
2050 %
2051 % Otherwise, it is close by.
2052 % \begin{macrocode}
2053 \else%
2054 \phfthm@proofref@impl@fmtcloseby{#1}{\autopageref{proof:#1}}%
2055 \fi%
2056 \fi%
2057 %% [\number\numexpr\phfthm@proofref@tmp@proofpage\relax{} vs % DEBUG
2058 %% \number\numexpr\phfthm@proofref@tmp@thispage\relax or % DEBUG
2059 %% \number\numexpr1+\phfthm@proofref@tmp@thispage\relax] % DEBUG
2060 }
2061 % \end{macrocode}
2062 % \end{macro}
2063 %
2064 %
2065 %
2066 % \begin{macro}{\phfthm@proofrefstyle@default@setup}
2067 % The main set-up macro for the |default| proof-ref style. It sets all the
2068 % call-backs to the default ones.
2069 % \begin{macrocode}
2070 \def\phfthm@proofrefstyle@default@setup{%
2071 \let\phfthm@proofref@impl@start\relax
2072 \let\phfthm@proofref@impl@afterlabel\@gobble
2073 \let\phfthm@proofref@impl@end\phfthm@proofrefstyle@default@main
2074 \let\phfthm@proofref@impl@fmtfarback\phfthm@proofrefstyle@default@fmtfarback
2075 \let\phfthm@proofref@impl@fmtfarahead\phfthm@proofrefstyle@default@fmtfarahead
2076 \let\phfthm@proofref@impl@fmtcloseby\phfthm@proofrefstyle@default@fmtcloseby
2077 \let\phfthm@proofref@impl@fmt\phfthm@proofrefstyle@default@fmt
2078 }
2079 % \end{macrocode}
2080 % \end{macro}
2081 %
2082 %
2083 % \subsubsection{Other proof-ref styles: \phfverb{margin} and \phfverb{marginbottom}}
2084 %
2085 % These styles simply use the same mechanism as the default style, but plug in
2086 % different sub-callbacks.
2087 %
2088 % Here's a command that actually places the marginpar:
2089 % \begin{macro}{\phfthmproofref@placemarginpar}
2090 % \begin{macrocode}
2091 \newcommand\phfthmproofref@placemarginpar[2]{%
2092 \marginpar[%
2093 \raggedleft #1%
2094 ]{%
2095 \raggedright #2%
2096 }%
2097 }
2098 % \end{macrocode}
2099 % \end{macro}
2100 %
2101 % \begin{macro}{\phfthmproofref@placephantommarginpar}
2102 % In the |marginbottom| proof-ref style, we place an invisible |\marginpar| at
2103 % the top of the proof so that the proof-ref margin note will not be shifted
2104 % too high when we try to align it to the bottom of the theorem statement. To
2105 % work around a weird bug in Rev\TeX, where I get the error message `command
2106 % sequence undefined: |\@captype|', I have found that a fix is to override
2107 % this local invisible |\marginpar| to locally make sure the |\@captype| is
2108 % defined. The wild fix I've found---no guarantees, there are dark magic
2109 % forces at work here---is the following, which you can include in your
2110 % document preamble if you're banging your head against this problem and
2111 % you're desperate:
2112 % \begin{verbatim}
2113 % \makeatletter
2114 % \renewcommand\phfthmproofref@placephantommarginpar{%
2115 % \begingroup\csdef{@captype}{figure}\marginpar{%
2116 % \vspace{-\baselineskip}\rule{0pt}{0pt}}\endgroup%
2117 % }
2118 % \makeatother
2119 % \end{verbatim}
2120 % \begin{macrocode}
2121 \newcommand\phfthmproofref@placephantommarginpar{%
2122 \leavevmode\marginpar{\vspace{-\baselineskip}\rule{\z@}{\z@}}%
2123 }%
2124 % \end{macrocode}
2125 % \end{macro}
2126 %
2127 %
2128 % \paragraph{The \phfverb{margin} style}
2129 %
2130 % \begin{macro}{\phfthm@proofrefstyle@margin@setup}
2131 % Set-up macro for the ``|margin|'' proof-ref style (displays the proof
2132 % reference in the margin of the page).
2133 % \begin{macrocode}
2134 \def\phfthm@proofrefstyle@margin@setup{%
2135 \phfthm@proofrefstyle@default@setup
2136 % \end{macrocode}
2137 %
2138 % The proof reference should be displayed directly at the top, not at the end of
2139 % the theorem, so plug in |\phfthm@proofref@default@main| onto |...@afterlabel|
2140 % and not onto |...@end|. Don't forget that these macros accept one argument,
2141 % the theorem label.
2142 % \begin{macrocode}
2143 \let\phfthm@proofref@impl@afterlabel\phfthm@proofrefstyle@default@main
2144 \let\phfthm@proofref@impl@end\@gobble
2145 % \end{macrocode}
2146 %
2147 % Define the formatting callback to put the note in the margin of the page using
2148 % a |\marginpar|. We need |\leavevmode| to make sure it's aligned properly
2149 % vertically with the paragraph.\footnote{See
2150 % \url{http://tex.stackexchange.com/a/16161/32188}}
2151 % \begin{macrocode}
2152 \def\phfthm@proofref@impl@fmt##1##2{%
2153 \leavevmode\phfthmproofref@placemarginpar{%
2154 \proofrefsize{\proofonname{##1}{##2}}%
2155 }{%
2156 \proofrefsize{\proofonname{##1}{##2}}%
2157 }%
2158 }%
2159 }
2160 % \end{macrocode}
2161 % \end{macro}
2162 %
2163 % \paragraph{The \phfverb{marginbottom} style}
2164 %
2165 % \begin{macro}{\phfthm@proofrefstyle@marginbottom@setup}
2166 % Set-up macro for the ``|marginbottom|'' proof-ref style (displays the proof
2167 % reference in the margin of the page).
2168 % \begin{macrocode}
2169 \def\phfthm@proofrefstyle@marginbottom@setup{%
2170 \phfthm@proofrefstyle@default@setup
2171 % \end{macrocode}
2172 %
2173 % The proof reference should be displayed directly at the bottom, not at the end
2174 % of the theorem, so plug in |\phfthm@proofref@default@main| onto |...@end| and
2175 % not onto |...@afterlabel|. Don't forget that these macros accept one
2176 % argument, the theorem label. In |...@afterlabel| we place a dummy marginpar
2177 % with an invisible rule one |\baselineskip| upwards, so that we force any
2178 % proof-ref marginpar not to extend above the top of the theorem statement.
2179 % \begin{macrocode}
2180 \def\phfthm@proofref@impl@afterlabel##1{%
2181 \phfthmproofref@placephantommarginpar
2182 }%
2183 \let\phfthm@proofref@impl@end\phfthm@proofrefstyle@default@main
2184 % \end{macrocode}
2185 %
2186 % Define the formatting callback to put the note in the margin of the page using
2187 % a |\marginpar|. We use a trick to align the margin note with the bottom of
2188 % the paragraph.\footnote{\url{https://tex.stackexchange.com/a/388018/32188}}
2189 % \begin{macrocode}
2190 \def\phfthm@proofref@impl@fmt##1##2{%
2191 \phfthmproofref@marginbottom@domarginpar{##1}{##2}%
2192 }%
2193 }
2194 \def\phfthmproofref@marginbottom@domarginpar#1#2{%
2195 \setbox\phfthm@tmp@boxa=\hbox to \marginparwidth{%
2196 \parbox[b]{\marginparwidth}{\raggedleft\sloppy
2197 \proofrefsize{\strut\proofonname{#1}{#2}\strut}}}%
2198 \setbox\phfthm@tmp@box=\hbox to \marginparwidth{%
2199 \parbox[b]{\marginparwidth}{\raggedright\sloppy
2200 \proofrefsize{\strut\proofonname{#1}{#2}\strut}}}%
2201 \phfthmproofref@placemarginpar{%
2202 \box\phfthm@tmp@boxa%
2203 }{%
2204 \box\phfthm@tmp@box%
2205 }%
2206 }
2207 \newbox\phfthm@tmp@box
2208 \newbox\phfthm@tmp@boxa
2209 % \end{macrocode}
2210 % \end{macro}
2211 %
2212 %
2213 % \subsection{Thmheading definition-like environments}
2214 %
2215 %
2216 % \subsubsection{Manually define a thmheading environment}
2217 %
2218 % Define the key-value options accepted by |\phfMakeThmheadingEnvironment|.
2219 % \begin{macrocode}
2220 \define@cmdkey{phfthmmkthmheading}{thmstyle}{}
2221 \define@cmdkey{phfthmmkthmheading}{internalcounter}{}
2222 % \end{macrocode}
2223 %
2224 % \begin{macrocode}
2225 \newcounter{phfthmheadingcounter}%
2226 % \end{macrocode}
2227 %
2228 % \begin{macro}{\phfMakeThmheadingEnvironment}
2229 %
2230 % Creates a new environment |\begin{thmheading}{Title}...\end{thmheading}| for
2231 % customizing the heading on-the-fly (see documentation in
2232 % \autoref{sec:thmheading}). Useful for an alternative formatting of
2233 % definitions. The syntax is:
2234 %
2235 % \noindent|\phfMakeThmheadingEnvironment|\oarg{key-value options}\marg{environment name}
2236 %
2237 % You can also use |\label| and |\ref| (the latter simply displays the given
2238 % title).
2239 %
2240 %
2241 % \begin{macrocode}
2242 \newcommand\phfMakeThmheadingEnvironment[2][]{% }
2243 % \end{macrocode}
2244 %
2245 % Parse the options. First set defaults, and then parse the input string.
2246 % \begin{macrocode}
2247 \def\cmdKV@phfthmmkthmheading@thmstyle{plain}%
2248 \def\cmdKV@phfthmmkthmheading@internalcounter{phfthmheadingcounter}%
2249 \setkeys{phfthmmkthmheading}{#1}%
2250 % \end{macrocode}
2251 %
2252 % And now, produce the relevant definitions:
2253 % \begin{macrocode}
2254 \csdef{phfthm@thmheading@#2@val@title}{$\langle$No Title Given$\rangle$}%
2255 \theoremstyle{\cmdKV@phfthmmkthmheading@thmstyle}%
2256 % \end{macrocode}
2257 %
2258 % We use |\newtheorem*| to create an unnumbered theorem. The fixed title is just
2259 % a single token, the macro which will be set to the relevant title at the last
2260 % moment.
2261 % \begin{macrocode}
2262 \newtheorem*{phfthm@internal@thmheading@#2}{%
2263 \csname phfthm@thmheading@#2@val@title\endcsname}%
2264 % \end{macrocode}
2265 %
2266 % Define the actual environment.
2267 % \begin{macrocode}
2268 \newenvironment{#2}[1]{%}
2269 \csdef{phfthm@thmheading@#2@val@title}{##1}%
2270 \letcs\thephfthmheadingcounter{phfthm@thmheading@#2@val@title}%
2271 % \end{macrocode}
2272 % Relay call to the internal \textit{AMS}-defined ``theorem:''
2273 % \begin{macrocode}
2274 \csname phfthm@internal@thmheading@#2\endcsname%
2275 % \end{macrocode}
2276 % Pin down an anchor. The use of |\hspace*{0pt}| is explained at
2277 % \url{http://tex.stackexchange.com/a/88493/32188} (see especially the first
2278 % comment).
2279 % \begin{macrocode}
2280 \hspace*{0pt}\refstepcounter{\cmdKV@phfthmmkthmheading@internalcounter}%
2281 \csname phfthm@hook@thmheading@#2@start\endcsname{##1}%
2282 % \end{macrocode}
2283 % Also, let's add some flexibility in the hspace:
2284 % \begin{macrocode}
2285 \hskip 0em plus 0.5em minus 0em%
2286 \ignorespaces%
2287 }%
2288 % \end{macrocode}
2289 %
2290 % Now, the END part of the environment: just call the callback and close the
2291 % internal AMS-defined theorem.
2292 % \begin{macrocode}
2293 {%
2294 \csname phfthm@hook@thmheading@#2@end\endcsname%
2295 \csname endphfthm@internal@thmheading@#2\endcsname%
2296 }%
2297 % \end{macrocode}
2298 %
2299 % Also define the relevant callbacks, which just relay their calls to the
2300 % default callbacks.
2301 % \begin{macrocode}
2302 \csdef{phfthm@hook@thmheading@#2@start}##1{%
2303 \phfthm@hook@thmheading@start{##1}}%
2304 \csdef{phfthm@hook@thmheading@#2@end}{\phfthm@hook@thmheading@end}%
2305 }
2306 % \end{macrocode}
2307 %
2308 % Provide as well the obsolete command |\phfthmMakeThmheadingEnvironment| which
2309 % was provided in earlier versions of this package:
2310 % \begin{macrocode}
2311 \def\phfthmMakeThmheadingEnvironment{\phfMakeThmheadingEnvironment}
2312 % \end{macrocode}
2313 % \end{macro}
2314 %
2315 %
2316 % \begin{macro}{\phfthm@hook@thmheading@start}
2317 % \begin{macro}{\phfthm@hook@thmheading@end}
2318 % Global callbacks which are called for all thmheading-type environments
2319 % defined with |\phfMakeThmheadingEnvironment| (unless their hooks have
2320 % been changed in order for them not to call these global hooks).
2321 % \begin{macrocode}
2322 \def\phfthm@hook@thmheading@start#1{}
2323 \def\phfthm@hook@thmheading@end{}
2324 % \end{macrocode}
2325 % \end{macro}
2326 % \end{macro}
2327 %
2328 %
2329 % \subsection{Theorem sets}
2330 %
2331 % Here, we define the theorem sets proposed by the package for quick loading.
2332 %
2333 % We first define the names. These are defined in any case regardless of
2334 % whether we are loading a theorem set or of which theorem set we are loading.
2335 % \begin{macrocode}
2336 \def\theoremname{Theorem}
2337 \def\propositionname{Proposition}
2338 \def\lemmaname{Lemma}
2339 \def\corollaryname{Corollary}
2340 \def\conjecturename{Conjecture}
2341 \def\remarkname{Remark}
2342 \def\definitionname{Definition}
2343 \def\ideaname{Idea}
2344 \def\questionname{Question}
2345 \def\claimname{Claim}
2346 \def\observationname{Observation}
2347 \def\problemname{Problem}
2348 % \end{macrocode}
2349 %
2350 % As we define the theorem sets, remember the names in a comma-separated list
2351 % which we can display in help text. The |\phfthm@def@thmset| replaces the
2352 % |\def| command and expects the definitions to follow immediately.
2353 % \begin{macrocode}
2354 \def\phfthm@def@thmset@optlist{}
2355 \def\phfthm@def@thmset#1{%
2356 \appto\phfthm@def@thmset@optlist{#1,}\csdef{phfthm@thmset@#1}}
2357 % \end{macrocode}
2358 %
2359 %
2360 % \begin{macro}{\phfthm@def@thmset@mktheorem}
2361 % \begin{macro}{\phfthm@def@thmset@mkdefn}
2362 % In definitions of theorem sets, use these macros to define a new
2363 % theorem-like environment (theorem, proposition, corollary, etc.) or
2364 % definition-like environment (definition, remark). The macros
2365 % |\phfthm@val@mkthmoptarg@theorem| and |\phfthm@val@mkthmoptarg@defn| are
2366 % defined by |\phfLoadThmSet|.
2367 % \begin{macrocode}
2368 \def\phfthm@def@thmset@mktheorem{%
2369 \expandafter\phfMakeTheorem\phfthm@val@mkthmoptarg@theorem}
2370 \def\phfthm@def@thmset@mkdefn{%
2371 \expandafter\phfMakeTheorem\phfthm@val@mkthmoptarg@defn}
2372 % \end{macrocode}
2373 % \end{macro}
2374 % \end{macro}
2375 %
2376 % The default set (empty name, or name ``|empty|'') provides no theorem. (The
2377 % first line uses |\def| directly so that we don't include an empty item in the
2378 % list of available choices.)
2379 % \begin{macrocode}
2380 \def\phfthm@thmset@{}
2381 \phfthm@def@thmset{empty}{}
2382 % \end{macrocode}
2383 %
2384 % Theorem set |simple|:
2385 % \begin{macrocode}
2386 \phfthm@def@thmset{simple}{
2387 \phfthm@def@thmset@mktheorem{theorem}{\theoremname}
2388 \phfthm@def@thmset@mktheorem{proposition}{\propositionname}
2389 \phfthm@def@thmset@mktheorem{lemma}{\lemmaname}
2390 \phfthm@def@thmset@mktheorem{corollary}{\corollaryname}
2391 \phfthm@def@thmset@mkdefn{definition}{\definitionname}
2392 }
2393 % \end{macrocode}
2394 %
2395 % Theorem set |default|:
2396 % \begin{macrocode}
2397 \phfthm@def@thmset{default}{
2398 \phfthm@def@thmset@mktheorem{theorem}{\theoremname}
2399 \phfthm@def@thmset@mktheorem{proposition}{\propositionname}
2400 \phfthm@def@thmset@mktheorem{lemma}{\lemmaname}
2401 \phfthm@def@thmset@mktheorem{corollary}{\corollaryname}
2402 \phfthm@def@thmset@mktheorem{conjecture}{\conjecturename}
2403 \phfthm@def@thmset@mktheorem{remark}{\remarkname}
2404 \phfthm@def@thmset@mkdefn{definition}{\definitionname}
2405 }
2406 % \end{macrocode}
2407 %
2408 % Theorem set |shortnames|:
2409 % \begin{macrocode}
2410 \phfthm@def@thmset{shortnames}{
2411 \phfthm@def@thmset@mktheorem{thm}{\theoremname}
2412 \phfthm@def@thmset@mktheorem{prop}{\propositionname}
2413 \phfthm@def@thmset@mktheorem{lem}{\lemmaname}
2414 \phfthm@def@thmset@mktheorem{cor}{\corollaryname}
2415 \phfthm@def@thmset@mktheorem{conj}{\conjecturename}
2416 \phfthm@def@thmset@mktheorem{rem}{\remarkname}
2417 \phfthm@def@thmset@mkdefn{defn}{\definitionname}
2418 }
2419 % \end{macrocode}
2420 %
2421 % Theorem set |rich|. Add definitions to the |default| set:
2422 % \begin{macrocode}
2423 \phfthm@def@thmset{rich}{
2424 \phfthm@thmset@default
2425 \phfthm@def@thmset@mktheorem{idea}{\ideaname}
2426 \phfthm@def@thmset@mktheorem{question}{\questionname}
2427 \phfthm@def@thmset@mktheorem{claim}{\claimname}
2428 \phfthm@def@thmset@mktheorem{observation}{\observationname}
2429 \phfthm@def@thmset@mktheorem{problem}{\problemname}
2430 }
2431 % \end{macrocode}
2432 %
2433 %
2434 % \begin{macro}{\phfLoadThmSet}
2435 % The macro |\phfLoadThmSet| loads a theorem set. See documentation at
2436 % \autoref{sec:load-thm-set-manually}.
2437 %
2438 % |#1| = options to |\phfMakeTheorem| for theorem-like environments
2439 %
2440 % |#2| = options to |\phfMakeTheorem| for definition-like environments
2441 %
2442 % |#3| = name of the theorem set to load
2443 %
2444 % \begin{macrocode}
2445 \newcommand\phfLoadThmSet[3]{%
2446 \ifcsname phfthm@thmset@#3\endcsname%
2447 \edef\phfthm@val@mkthmoptarg@theorem{#1}%
2448 \edef\phfthm@val@mkthmoptarg@defn{#2}%
2449 \csname phfthm@thmset@#3\endcsname%
2450 \else%
2451 \PackageWarning{phfthm}{Unknown theorem set: `#3'!}%
2452 \fi%
2453 }
2454 % \end{macrocode}
2455 %
2456 % For compatibility with my earlier versions of \pkgname{phfthm}, also provide
2457 % the obsolete |\phfthmLoadThmSet|:
2458 % \begin{macrocode}
2459 \def\phfthmLoadThmSet{\phfLoadThmSet}
2460 % \end{macrocode}
2461 % \end{macro}
2462 %
2463 %
2464 % \subsection{Package option handling}
2465 %
2466 % The machinery is in place, now define and parse the package options.
2467 %
2468 % \subsubsection{Declaring the package options}
2469 %
2470 % The package options all use the |keyval| parsing mechanism using the
2471 % \pkgname{xkeyval} package.
2472 %
2473 % Recall when using |\define@XXXkey| that the optional argument after the second
2474 % mandatory argument is the value which is assumed if the key is given with no
2475 % explicit value; it is not the initial default value.
2476 %
2477 % \paragraph{The \pkgoptionfmt{resetstyle} package option}
2478 % An option to reset all options so that the package provides only stand-alone
2479 % definitions and is not invasive (see \autoref{sec:global-pkg-options}).
2480 %
2481 % This option does not expect any argument (i.e., you should specify
2482 % |\usepackage[resetstyle,|\meta{other options}|]{phfthm}|, and not
2483 % |\usepackage[resetstyle=true,|\meta{other options}|]{phfthm}|).
2484 % \begin{macrocode}
2485 \define@key{phfthmpkg}{resetstyle}[]{%
2486 \KV@phfthmpkg@smallproofsfalse%
2487 \KV@phfthmpkg@qedsymbolblacksquarefalse%
2488 \KV@phfthmpkg@prooftitleitbffalse%
2489 \KV@phfthmpkg@sepcountersfalse%
2490 \KV@phfthmpkg@countpersectionfalse%
2491 \KV@phfthmpkg@proofreffalse%
2492 \if\relax\detokenize{#1}\relax\else%
2493 \PackageError{phfthm}{'resetstyle' does not take any argument.}{You
2494 specified the 'resetstyle' argument and provided a value to it
2495 ('resetstyle=...'). However the 'resetstyle' option does not accept
2496 any value argument.}
2497 \fi%
2498 }
2499 % \end{macrocode}
2500 %
2501 %
2502 % \paragraph{Options for loading theorem sets}
2503 % Define the various package options for the loading of predefined theorem sets
2504 % (\autoref{sec:theorem-sets}).
2505 %
2506 % The \pkgoptionfmt{sepcounters} option, off by default.
2507 % \begin{macrocode}
2508 \define@boolkey{phfthmpkg}{sepcounters}[true]{}
2509 \KV@phfthmpkg@sepcountersfalse
2510 % \end{macrocode}
2511 %
2512 % The \pkgoptionfmt{countpersection} option, off by default.
2513 % \begin{macrocode}
2514 \define@boolkey{phfthmpkg}{countpersection}[true]{}
2515 \KV@phfthmpkg@countpersectionfalse
2516 % \end{macrocode}
2517 %
2518 %
2519 % The \pkgoptionfmt{proofref} option. The proof-ref is on initially by default.
2520 % \begin{macrocode}
2521 \newif\ifKV@phfthmpkg@proofref
2522 \KV@phfthmpkg@proofreftrue
2523 \def\cmdKV@phfthmpkg@proofref@style{default}
2524 % \end{macrocode}
2525 % Actually define the option itself. Here we do some customized parsing of the
2526 % value of the |proofref=...| option, to treat the cases |proofref=| (empty
2527 % argument) and |proofref=false| separately.
2528 % \begin{macrocode}
2529 \define@key{phfthmpkg}{proofref}[]{%
2530 \ifblank{#1}{%
2531 % \end{macrocode}
2532 % If a blank argument provided, set some sensible defaults with proofref on:
2533 % \begin{macrocode}
2534 \KV@phfthmpkg@proofreftrue%
2535 \def\cmdKV@phfthmpkg@proofref@style{default}%
2536 }{%
2537 % \end{macrocode}
2538 % Otherwise, check to see if the value is |false|, in which case deactivate the
2539 % proof-ref mechanism, or else, activate it and set the given style value as
2540 % documented in \autoref{sec:theorem-sets}.
2541 % \begin{macrocode}
2542 \ifstrequal{#1}{false}{%
2543 \KV@phfthmpkg@proofreffalse%
2544 }{%
2545 \KV@phfthmpkg@proofreftrue%
2546 \def\cmdKV@phfthmpkg@proofref@style{#1}%
2547 }%
2548 }%
2549 }
2550 % \end{macrocode}
2551 %
2552 % The \pkgoptionfmt{thmset} option. We subtly construct the command
2553 % |\define@choicekey{phfthmpkg}{thmset}[\val]{\phfthm@def@thmset@optlist}|, but
2554 % with the last macro (option list) expanded.
2555 % \begin{macrocode}
2556 \def\@tmpa{\define@choicekey{phfthmpkg}{thmset}[\val]}
2557 \edef\@tmpb{{\phfthm@def@thmset@optlist}}
2558 \expandafter\@tmpa\@tmpb{%
2559 \xdef\cmdKV@phfthmpkg@thmset{\val}%
2560 }
2561 % \end{macrocode}
2562 % By default we should load the |default| set.
2563 % \begin{macrocode}
2564 \def\cmdKV@phfthmpkg@thmset{default}
2565 % \end{macrocode}
2566 %
2567 %
2568 % The options \pkgoptionfmt{theoremstyle} and \pkgoptionfmt{definitionstyle} set
2569 % which theorem style to use for theorems and definitions, when loading the
2570 % given thmset.
2571 % \begin{macrocode}
2572 \define@cmdkey{phfthmpkg}{theoremstyle}{}
2573 \def\cmdKV@phfthmpkg@theoremstyle{plain}
2574 \define@cmdkey{phfthmpkg}{definitionstyle}{}
2575 \def\cmdKV@phfthmpkg@definitionstyle{definition}
2576 % \end{macrocode}
2577 %
2578 %
2579 % \paragraph{Proof environment options}
2580 % Define the package options \pkgoptionfmt{proofenv},
2581 % \pkgoptionfmt{smallproofs}, \pkgoptionfmt{qedsymbolblacksquare}, and
2582 % \pkgoptionfmt{prooftitleitbf} (\autoref{sec:proof-env}).
2583 % \begin{macrocode}
2584 \define@boolkey{phfthmpkg}{proofenv}[true]{}
2585 \define@boolkey{phfthmpkg}{smallproofs}[true]{}
2586 \define@boolkey{phfthmpkg}{qedsymbolblacksquare}[true]{}
2587 \define@boolkey{phfthmpkg}{prooftitleitbf}[true]{}
2588 % \end{macrocode}
2589 %
2590 % Set the initial default values for these options.
2591 % \begin{macrocode}
2592 \KV@phfthmpkg@smallproofstrue
2593 \KV@phfthmpkg@qedsymbolblacksquaretrue
2594 \KV@phfthmpkg@proofenvtrue
2595 \KV@phfthmpkg@prooftitleitbffalse
2596 % \end{macrocode}
2597 %
2598 %
2599 % \paragraph{Options for a theorem-like heading environment}
2600 % Define the \pkgoptionfmt{thmheading} and \pkgoptionfmt{thmheadingstyle}
2601 % package options, documented in \autoref{sec:thmheading}.
2602 % \begin{macrocode}
2603 \define@boolkey{phfthmpkg}{thmheading}[true]{}
2604 \define@cmdkey{phfthmpkg}{thmheadingstyle}{}
2605 % \end{macrocode}
2606 %
2607 % The |thmheading| environment is provided by default; it's a stand-alone
2608 % definition anyway. The style defaults to the |plain| style.
2609 % \begin{macrocode}
2610 \KV@phfthmpkg@thmheadingtrue
2611 \def\cmdKV@phfthmpkg@thmheadingstyle{plain}
2612 % \end{macrocode}
2613 %
2614 %
2615 % \subsubsection{Parsing the package options}
2616 % The usual stuff (\pkgname{xkeyval}-flavored).
2617 % \begin{macrocode}
2618 \DeclareOptionX*{%
2619 \PackageWarning{phfthm}{Invalid option: `\CurrentOption'}%
2620 }
2621 \ProcessOptionsX<phfthmpkg>
2622 % \end{macrocode}
2623 %
2624 %
2625 % \subsubsection{Execute package options-controlled actions}
2626 %
2627 % \paragraph{Loading a theorem set}
2628 % First, we need to take into account the options which alter the way the
2629 % theorem sets will be loaded (separate counters, proof-ref, etc.).
2630 %
2631 % Take care of the proof-ref stuff. First, define the possible styles (note
2632 % that these are not the same as the values to the |proofrefstyle| argument to
2633 % the |\phfMakeTheorem| command).
2634 % \begin{macrocode}
2635 \def\phfthm@val@mkthmopt@proofrefstyle{}
2636 \ifKV@phfthmpkg@proofref
2637 \def\phfthm@proofref@style@default{}
2638 \def\phfthm@proofref@style@{}
2639 % \end{macrocode}
2640 % Note that |proofref=always| and |proofref=onlyifveryfar| have a global effect,
2641 % because they set |\phfProofrefPageBackTolerance| and
2642 % |\phfProofrefPageAheadTolerance| (see documentation in
2643 % \autoref{sec:theorem-sets}).
2644 % \begin{macrocode}
2645 \def\phfthm@proofref@style@always{
2646 \def\phfProofrefPageBackTolerance{-1}
2647 \def\phfProofrefPageAheadTolerance{-1}
2648 }
2649 \def\phfthm@proofref@style@onlyifveryfar{
2650 \def\phfProofrefPageBackTolerance{2}
2651 \def\phfProofrefPageAheadTolerance{4}
2652 }
2653 \def\phfthm@proofref@style@margin{
2654 \def\phfthm@val@mkthmopt@proofrefstyle{proofrefstyle=margin}
2655 }
2656 \def\phfthm@proofref@style@marginbottom{
2657 \def\phfthm@val@mkthmopt@proofrefstyle{proofrefstyle=marginbottom}
2658 }
2659 \def\phfthm@proofref@style@longref{
2660 % \end{macrocode}
2661 % For |longref|: by setting |\proofonname| globally, this option can be combined
2662 % with other styles. But then we also change the default style formatting to
2663 % avoid ugly line breaks.
2664 % \begin{macrocode}
2665 \def\proofonname##1##2{The proof of this \phfthm@autorefnameof{##1} can
2666 be found on ##2.}
2667 \def\phfthm@proofrefstyle@default@fmt##1##2{%
2668 \par{\raggedleft\proofrefsize{(\proofonname{##1}{##2})}\par}%
2669 }
2670 }
2671 \def\phfthm@proofref@style@off{
2672 \def\phfthm@val@mkthmopt@proofrefstyle{proofref=false}
2673 }
2674 % \end{macrocode}
2675 %
2676 % Now execute the given styles. Construct the command
2677 % |\phfthm@internal@execattribs{phfthm@proofref@style@}|\hspace
2678 % {0pt}|{ProofRef Style}|\hspace{0pt}|{\cmdKV@phfthmpkg@proofref@style}|, but with
2679 % the last macro expanded.
2680 % \begin{macrocode}
2681 \def\x{%
2682 \phfthm@internal@execattribs{phfthm@proofref@style@}{ProofRef Style}}
2683 \expandafter\x\expandafter{\cmdKV@phfthmpkg@proofref@style}
2684 % \end{macrocode}
2685 %
2686 % Prepare the proof-ref option in case we don't want any proof reference
2687 % mechanism on.
2688 %
2689 % \changed[chg-bugfix-pkgopt-proofreffalse]{v1.1}{2019/03/12}{Bug fix: package
2690 % option \texttt{proofref\eqsign false} didn't have any effect}
2691 % \begin{macrocode}
2692 \else
2693 \def\phfthm@val@mkthmopt@proofrefstyle{proofref=false}
2694 \fi
2695 % \end{macrocode}
2696 %
2697 %
2698 % Take care of counters. In any case, define a common counter, in case we use a
2699 % common counter for all theorem types. (The counter is defined in any case, to
2700 % avoid breaking other code which might use it if suddenly the user decides to
2701 % use |sepcounters=true| for their document.)
2702 % \begin{macrocode}
2703 \newcounter{phfthmcounter}
2704 \setcounter{phfthmcounter}{0}
2705 % \end{macrocode}
2706 %
2707 % Prepare an argument to |\phfMakeTheorem| according to the
2708 % \pkgoptionfmt{countpersection} and \pkgoptionfmt{sepcounters} options. First
2709 % determine the parent counter in case \pkgoptionfmt{countpersection} is set
2710 % (|chapter| if |chapter| counter exists, else |section|).
2711 % \begin{macrocode}
2712 \ifKV@phfthmpkg@countpersection
2713 \ifcsname c@chapter\endcsname
2714 \def\phfthm@tmp@parentcountername{chapter}
2715 \else
2716 \def\phfthm@tmp@parentcountername{section}
2717 \fi
2718 \fi
2719 \ifKV@phfthmpkg@sepcounters
2720 \ifKV@phfthmpkg@countpersection
2721 \edef\phfthm@val@mkthmopt@counteropts{parentcounter=\phfthm@tmp@parentcountername}
2722 \else
2723 \def\phfthm@val@mkthmopt@counteropts{}
2724 \fi
2725 \else
2726 \def\phfthm@val@mkthmopt@counteropts{counter=phfthmcounter}
2727 \ifKV@phfthmpkg@countpersection
2728 \numberwithin{phfthmcounter}{\phfthm@tmp@parentcountername}
2729 \fi
2730 \fi
2731 % \end{macrocode}
2732 %
2733 %
2734 % Finally, load the theorem set defined by the options. The first argument
2735 % regroups the options for theorem environments (Theorem, Proposition,
2736 % Corollary, \ldots); the second argument regroups the options for definition
2737 % environments (Definition); the third argument is the theorem set name itself.
2738 % \begin{macrocode}
2739 \phfLoadThmSet%
2740 {[\phfthm@val@mkthmopt@counteropts,\phfthm@val@mkthmopt@proofrefstyle,
2741 thmstyle=\cmdKV@phfthmpkg@theoremstyle]}%
2742 {[\phfthm@val@mkthmopt@counteropts,proofref=false,
2743 thmstyle=\cmdKV@phfthmpkg@definitionstyle]}%
2744 {\cmdKV@phfthmpkg@thmset}
2745 % \end{macrocode}
2746 % (Note the absence of the proof-ref for definitions.)
2747 %
2748 % \paragraph{Define the proof environment}
2749 % If requested, define the |proof| environment (\autoref{sec:proof-env}).
2750 % First, make sure we take into account the options \pkgoptionfmt{smallproofs},
2751 % \pkgoptionfmt{qedsymbolblacksquare} and \pkgoptionfmt{prooftitleitbf}.
2752 % \begin{macrocode}
2753 \def\phfthm@pkgopterr@require@proofenv#1{%
2754 \ifKV@phfthmpkg@proofenv\else%
2755 \PackageError{phfthm}{Option `#1' depends on `proofenv=true'}%
2756 \fi
2757 }
2758 \ifKV@phfthmpkg@smallproofs
2759 %\phfthm@pkgopterr@require@proofenv{smallproofs}
2760 \apptocmd\phfthm@hookproof@startcommon{%
2761 \def\baselinestretch{1.2}\footnotesize}{}{%
2762 Failed to change command \string\phfthm@hook@start@proof}
2763 \fi
2764 \ifKV@phfthmpkg@qedsymbolblacksquare
2765 %\phfthm@pkgopterr@require@proofenv{qedsymbolblacksquare}
2766 \RequirePackage{amssymb}
2767 \providecommand\filledsquare{\ensuremath{\blacksquare}}
2768 \renewcommand\qedsymbol{\text{\tiny\ensuremath{\filledsquare}}}
2769 \fi
2770 \ifKV@phfthmpkg@prooftitleitbf
2771 %\phfthm@pkgopterr@require@proofenv{prooftitleitbf}
2772 \def\phfthm@ProofTitleFmt#1{{\itshape\bfseries#1.}}
2773 \fi
2774 % \end{macrocode}
2775 % Go ahead and define the |proof| environment. Because we have already loaded
2776 % \pkgname{amsthm}, we need to override the existing |proof| environment.
2777 % \begin{macrocode}
2778 \ifKV@phfthmpkg@proofenv
2779 \phfMakeProofEnv[override=true]{proof}
2780 \fi
2781 % \end{macrocode}
2782 %
2783 % \paragraph{Define the theorem-heading environment}
2784 % Define the |thmheading| environment, if requested.
2785 % \begin{macrocode}
2786 \ifKV@phfthmpkg@thmheading
2787 \phfMakeThmheadingEnvironment%
2788 [thmstyle=\cmdKV@phfthmpkg@thmheadingstyle]{thmheading}
2789 \fi
2790 % \end{macrocode}
2791 %
2792 %\Finale
2793 \endinput