Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2016-2026 by Pierre Senellart
4 %
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained'.
14 %
15 % The Current Maintainer of this work is Pierre Senellart
16 % <[email protected]> and a version control system for this work
17 % is available at http://github.com/PierreSenellart/apxproof
18 %
19 % This work consists of the files apxproof.dtx and apxproof.ins
20 % and the derived file apxproof.sty.
21 %
22 % \fi
23 %
24 % \iffalse
25 %<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
26 %<package>\ProvidesPackage{apxproof}
27 %<package> [2026/05/14 v1.4.0 Automatic proofs in appendix]
28 %
29 %<*driver>
30 \documentclass{ltxdoc}
31 \usepackage{apxproof}
32 \usepackage{hypdoc}
33 \usepackage{textcomp}
34 \usepackage[TS1,T1]{fontenc}
35 \usepackage{lmodern}
36 \usepackage{microtype}
37 \newtheorem{example}{Example}
38 \newtheoremrep{foobar}{Foobar}
39 \newtheoremrep*{foobarstar}{Foobarstar}
40 \EnableCrossrefs
41 \CodelineIndex
42 \RecordChanges
43 \begin{document}
44 \DocInput{apxproof.dtx}
45 \end{document}
46 %</driver>
47 % \fi
48 %
49 % \CheckSum{1275}
50 %
51 % \CharacterTable
52 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
53 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
54 % Digits \0\1\2\3\4\5\6\7\8\9
55 % Exclamation \! Double quote \" Hash (number) \#
56 % Dollar \$ Percent \% Ampersand \&
57 % Acute accent \' Left paren \( Right paren \)
58 % Asterisk \* Plus \+ Comma \,
59 % Minus \- Point \. Solidus \/
60 % Colon \: Semicolon \; Less than \<
61 % Equals \= Greater than \> Question mark \?
62 % Commercial at \@ Left bracket \[ Backslash \\
63 % Right bracket \] Circumflex \^ Underscore \_
64 % Grave accent \` Left brace \{ Vertical bar \|
65 % Right brace \} Tilde \~}
66 %
67 % \changes{v1.0.4}{2017/03/02}{Show options commented on in margin and index}
68 %\iffalse
69 % Taken from xkeyval.dtx
70 %\fi
71 %\makeatletter
72 %\def\DescribeOption#1{\leavevmode\@bsphack
73 % \marginpar{\raggedleft\PrintDescribeOption{#1}}%
74 % \SpecialOptionIndex{#1}\@esphack\ignorespaces}
75 %\def\PrintDescribeOption#1{\strut\emph{option}\\\MacroFont #1\ }
76 %\def\SpecialOptionIndex#1{\@bsphack
77 % \index{#1\actualchar{\protect\ttfamily#1}
78 % (option)\encapchar usage}%
79 % \index{options:\levelchar#1\actualchar{\protect\ttfamily#1}\encapchar
80 % usage}\@esphack}
81 %\def\DescribeOptions#1{\leavevmode\@bsphack
82 % \marginpar{\raggedleft\strut\emph{options}%
83 % \@for\@tempa:=#1\do{%
84 % \\\strut\MacroFont\@tempa\SpecialOptionIndex\@tempa
85 % }}\@esphack\ignorespaces}
86 %\makeatother
87 %
88 % \changes{v1.0.0}{2016/10/31}{Initial released version}
89 % \changes{v1.0.1}{2016/11/07}{Prevent empty bibliography environment;
90 % fix typos}
91 %
92 % \GetFileInfo{apxproof.sty}
93 %
94 % \makeatletter\c@IndexColumns=2\makeatother
95 % \DoNotIndex{
96 % \newcommand,\newenvironment,\end,\begin,\edef,\if,\else,\fi,\def,
97 % \begingroup,\endgroup,\csname,\let,\noexpand,\protect,\expandafter,
98 % \ifthenelse,\equal,\endcsname,\@empty,\@ifnotempty,\immediate,
99 % \addtocounter,\newcounter,\newtoggle,\global,\ifdefined,\iftoggle,
100 % \ifx,\jobname,\makeatletter,\makeatother,\newwrite,\NewEnviron,
101 % \patchcmd,\relax,\renewcommand,\renewenvironment,\RequirePackage,
102 % \roman,\space,\undefined,\unexpanded
103 % }
104 %
105 % \title{The \textsf{apxproof} package}
106 %
107 % \author{Pierre Senellart \\ \texttt{[email protected]} \\
108 % \url{http://github.com/PierreSenellart/apxproof}}
109 % \date{\filedate \quad \fileversion}
110 %
111 % \maketitle
112 %
113 % \begin{abstract}
114 % This package makes it easier to write articles where proofs and other material
115 % are deferred to the appendix. The appendix material is written in the \LaTeX{}
116 % code along with the main text which it naturally complements, and it is
117 % automatically deferred. The package can automatically send proofs to the
118 % appendix, can repeat in the appendix the theorem environments stated in the
119 % main text, can section the appendix automatically based on the sectioning of
120 % the main text, and supports a separate bibliography for the appendix material.
121 % \end{abstract}
122 %
123 % \section{Usage}
124 % The \textsf{apxproof} package is intended to simplify the writing of articles where some of
125 % the content needs to be deferred to an appendix. This is in particular
126 % useful for the submission of scientific articles to conferences or
127 % journals that limit the number of pages in the main text but allow an
128 % extra appendix, where proofs of theorems and other material can be added.
129 %
130 % \subsection{Basics}
131 % To use \textsf{apxproof}, first load it in the header of your document:
132 % \begin{quote}|\usepackage{apxproof}|\end{quote}
133 % On its own, this does not do anything and should not change the
134 % appearance of your document. To add an appendix with some material from
135 % your document, use the |toappendix| environment:
136 % \begin{quote}
137 % |\begin{toappendix}|\DescribeEnv{toappendix}\\
138 % \hspace*{1em}\dots\\
139 % |\end{toappendix}|
140 % \end{quote}
141 % The content will appear at the end of your document, in an
142 % automatically generated section that refers to the current section in the main
143 % text.
144 % \begin{example}
145 % Throughout this documentation, all examples produce content
146 % deferred to the appendix, at the very end of this document.
147 % \begin{verbatim}
148 % \begin{toappendix}
149 % This content is in the appendix.
150 % \end{toappendix}
151 % \end{verbatim}
152 % \begin{toappendix}
153 % This content is in the appendix.
154 % \end{toappendix}
155 % \end{example}
156 % \changes{v1.0.3}{2017/01/10}{Note on entire sections in appendix}
157 % When the content to put in appendix is an entire section, make sure
158 % that \verb|\section| is the very first command that appears within the
159 % \verb|toappendix| environment. It will disable the automatic production
160 % of a section heading.
161 % \subsection{Repeated Theorems and Proofs}
162 % In some scientific papers that include proofs, it is common to defer
163 % proofs to the appendix. This can easily be achieved using the
164 % |appendixproof| environment:
165 % \begin{quote}
166 % |\begin{appendixproof}|\DescribeEnv{appendixproof}\\
167 % \hspace*{1em}\dots\\
168 % |\end{appendixproof}|
169 % \end{quote}
170 % This behaves like the |toappendix| environment, except that
171 % a proof environment is generated.
172 % \begin{example}We now send a proof to the appendix:
173 % \begin{verbatim}
174 % \begin{appendixproof}
175 % This proof is in the appendix.
176 % \end{appendixproof}
177 % \end{verbatim}
178 % \begin{appendixproof}
179 % This proof is in the appendix.
180 % \end{appendixproof}
181 % \end{example}
182 %
183 % When deferring proofs to the appendix, an annoying problem is that the
184 % statement of the theorem remains in the main text; it is hard to read a
185 % proof that is far away from the statement it proves. \textsf{apxproof}
186 % offers two ways to address this. With
187 % |\newtheoremrep|\DescribeMacro{\newtheoremrep}, the statement
188 % of the theorem is \emph{repeated} in the appendix, immediately above
189 % the deferred proof. With the starred variant
190 % |\newtheoremrep*|\DescribeMacro{\newtheoremrep*}, the
191 % theorem is \emph{not} repeated, but the proof is still automatically
192 % deferred to the appendix; this is convenient when the proofs are short
193 % enough or close enough to the main text that a restatement would be
194 % redundant, especially when combined with the
195 % |\appendixproofname|\DescribeMacro{\appendixproofname}{} hook (see
196 % Section~\ref{sec:customization}) to title proofs with the type and
197 % number of the theorem they refer to (e.g., ``Proof of Theorem~1''). In
198 % summary, three behaviors are available for a theorem environment:
199 % \begin{description}
200 % \item[\textbackslash|newtheorem|] (\LaTeX's standard command):
201 % the theorem appears in the main text only; the |proof| environment is
202 % left unchanged by \textsf{apxproof}.
203 % \item[\textbackslash|newtheoremrep|]: the theorem appears in the main
204 % text \emph{and} is restated in the appendix above its proof; the
205 % |proof| that follows in the source is automatically deferred to the
206 % appendix.
207 % \item[\textbackslash|newtheoremrep*|]: the theorem appears in the
208 % main text only; the |proof| that follows is automatically deferred to
209 % the appendix, without restating the theorem there.
210 % \end{description}
211 % In all cases, theorems can share counters and a single document can
212 % mix the three behaviors freely.
213 %
214 % To use the repeated-theorem feature, you can define a new
215 % \emph{repeated theorem} environment using the |\newtheoremrep| command:
216 % \changes{v1.0.5}{2017/05/31}{Ability to specify a sectioning counter in newtheoremrep}
217 % \begin{quote}
218 % |\newtheoremrep|\marg{name}\oarg{counter}\marg{title}\oarg{countersec}\DescribeMacro{\newtheoremrep}
219 % \end{quote}
220 % or, equivalently, its starred form to obtain a \emph{proof-deferred}
221 % (but not repeated) theorem:
222 % \begin{quote}
223 % |\newtheoremrep*|\marg{name}\oarg{counter}\marg{title}\oarg{countersec}\DescribeMacro{\newtheoremrep*}
224 % \end{quote}
225 % Usage of either form is exactly the same as that of AMS \LaTeX{}'s
226 % |\newtheorem| macro:
227 % \begin{itemize}
228 % \item \meta{name} (e.g., |theorem|) is the name of an environment that is created for this kind of
229 % theorem;
230 % \item \meta{counter} (e.g., |definition|) is an optional counter describing
231 % from which kind of environment the numbering of these environments should be
232 % inherited;
233 % \item \meta{title}
234 % (e.g., |Theorem|) is
235 % the title that will be used to display this theorem environment;
236 % \item \meta{countersec} (e.g., |section|) is an optional counter of a
237 % sectioning command indicating that counters for this theorem should
238 % be prefixed by this counter (and reset at each occurrence of the
239 % sectioning command).
240 % \end{itemize}
241 % \meta{counter} and \meta{countersec} should not be used together.
242 % What
243 % differs from |\newtheorem| is that, when the following is written:
244 % \begin{quote}
245 % |\newtheoremrep{foobar}{Foobar}|
246 % \end{quote}
247 % then \emph{two} environments are defined: the \verb|foobar|
248 % environment, which behaves as if |\newtheorem| had been used, and the
249 % |foobarrep| environment, which results in the statement of this
250 % environment being repeated in the appendix.
251 % The starred form |\newtheoremrep*{foobarstar}{Foobarstar}| similarly
252 % defines two environments |foobarstar| and |foobarstarrep|, except that
253 % |\begin{foobarstarrep}| does not produce any restatement of the
254 % theorem in the appendix; only the following |proof| is deferred.
255 %
256 % One interesting feature of \textsf{apxproof} is that in most
257 % situations, there is no need to use the |appendixproof| environment.
258 % Indeed, the |proof| \DescribeEnv{proof} environment is redefined by \textsf{apxproof} to
259 % automatically put the proof either in the main text (if it follows a
260 % regular theorem) or in the appendix (if it follows a repeated
261 % theorem).
262 % \begin{example}
263 % Assume we have first defined a repeated theorem environment |foobar| as
264 % above.
265 % We can now use this theorem environment, first for a regular theorem in
266 % the main text, then for a theorem repeated in the main text and in the
267 % appendix:
268 % \begin{quote}
269 % \begin{verbatim}
270 % \begin{foobar}
271 % This foobar is a regular one, in the main text.
272 % \end{foobar}
273 % \begin{proof}
274 % This is the proof of the regular foobar.
275 % \end{proof}
276 % \end{verbatim}
277 % \end{quote}
278 % We obtain:
279 % \begin{foobar}
280 % This foobar is a regular one, in the main text.
281 % \end{foobar}
282 % \begin{proof}
283 % This is the proof of the regular foobar.
284 % \end{proof}
285 % Now, if we use a repeated theorem:
286 % \begin{quote}
287 % \begin{verbatim}
288 % \begin{foobarrep}
289 % This foobar is repeated in the appendix.
290 % \end{foobarrep}
291 % \begin{proof}
292 % This is the proof of the repeated foobar.
293 % \end{proof}
294 % \end{verbatim}
295 % \end{quote}
296 % We now obtain:
297 % \begin{foobarrep}
298 % This foobar is repeated in the appendix.
299 % \end{foobarrep}
300 % \begin{proof}
301 % This is the proof of the repeated foobar.
302 % \end{proof}
303 % Note that, since |hyperref| is loaded, there are hyperlinks
304 % created between the statements of the theorems in the main text and in
305 % the appendix.
306 % \end{example}
307 % \begin{example}
308 % In contrast, the starred form of |\newtheoremrep| produces a theorem
309 % whose proof is deferred to the appendix \emph{without} restating the
310 % theorem there. Assuming the declaration
311 % |\newtheoremrep*{foobarstar}{Foobarstar}| at the top of the document,
312 % writing:
313 % \begin{quote}
314 % \begin{verbatim}
315 % \begin{foobarstarrep}
316 % This foobar will not be repeated in the appendix,
317 % but the proof below will be deferred there.
318 % \end{foobarstarrep}
319 % \begin{proof}
320 % This is the proof of the (non-repeated) foobar.
321 % \end{proof}
322 % \end{verbatim}
323 % \end{quote}
324 % yields:
325 % \begin{foobarstarrep}
326 % This foobar will not be repeated in the appendix,
327 % but the proof below will be deferred there.
328 % \end{foobarstarrep}
329 % \begin{proof}
330 % This is the proof of the (non-repeated) foobar.
331 % \end{proof}
332 % In this mode, the title of the deferred proof in the appendix is
333 % controlled by the |\appendixproofname| hook documented in
334 % Section~\ref{sec:customization}; by default, this hook is empty, so
335 % proofs are titled simply ``Proof.'' as usual. The forward hyperlink
336 % from the theorem number in the main text (when \textsf{hyperref} is
337 % loaded) points to the location of the proof in the appendix.
338 % \end{example}
339 %
340 % When the proof is deferred to the appendix, it is common practice to
341 % add a proof sketch in the main text. \textsf{apxproof} defines a simple
342 % |proofsketch| environment for this purpose:
343 % \changes{v1.0.5}{2017/05/31}{Fix compilation of proofsketch environment in inline mode}
344 % \begin{quote}
345 % |\begin{proofsketch}|\DescribeEnv{proofsketch}\\
346 % \hspace*{1em}\dots\\
347 % |\end{proofsketch}|
348 % \end{quote}
349 % The proof sketch is typeset similarly to a proof, but is always in the
350 % main text. Similarly, an |inlineproof| \DescribeEnv{inlineproof}
351 % environment is provided so as to
352 % be able to have both a proof in the appendix (using the regular |proof|
353 % environment, or alternatively the |appendixproof| environment) and a
354 % different proof in the main text (using the |inlineproof| environment).
355 % \begin{example} Here are simple examples of proof sketches and inline
356 % proofs:
357 % \begin{verbatim}
358 % \begin{proofsketch}
359 % This is a proof sketch.
360 % \end{proofsketch}
361 % \end{verbatim}
362 % \begin{proofsketch}
363 % This is a proof sketch.
364 % \end{proofsketch}
365 % \begin{verbatim}
366 % \begin{inlineproof}
367 % This is an inline proof.
368 % \end{inlineproof}
369 % \end{verbatim}
370 % \begin{inlineproof}
371 % This is an inline proof.
372 % \end{inlineproof}
373 % \end{example}
374 %
375 % \subsection{Bibliography}
376 % By default, \textsf{apxproof} automatically adds a bibliography in the appendix
377 % with only the references cited in the appendix material. This allows for a
378 % clean separation of references used solely in the main text, and those
379 % used in the appendix.
380 % \begin{example}
381 % Assume we have citations both in the main text and in the appendix.
382 % \begin{verbatim}
383 % This is a citation in the main text~\cite{lamport86}.
384 % \begin{toappendix}
385 % This is a citation in the appendix~\cite{proofsAreHard}.
386 % \end{toappendix}
387 % \end{verbatim}
388 % This is a citation in the main text~\cite{lamport86}.
389 % \begin{toappendix}
390 % This is a citation in the appendix~\cite{proofsAreHard}.
391 % \end{toappendix}
392 % \end{example}
393 % The bibliography in the appendix can use
394 % a different style and heading than the bibliography in the main text (and, by
395 % default, it does). See
396 % Section~\ref{sec:customization} for how to configure the appearance of
397 % that bibliography.
398 %
399 % \DescribeOption{bibliography}
400 % In order to use a single appendix for the main text and the
401 % bibliography, one can specify the
402 % value |common| to the |bibliography| option when loading the package.
403 %
404 % \DescribeOption{bibengine}
405 % By default, \textsf{apxproof} relies on the \textsf{bibunits} package
406 % to typeset a separate bibliography for the appendix material; this is
407 % the |bibengine=bibtex| mode (the default), suitable for documents
408 % that use \textsf{bibtex} (with or without \textsf{natbib}) for
409 % citations and references. Documents using \textsf{biblatex} can
410 % instead set |bibengine=biblatex|, in which case \textsf{apxproof}
411 % wraps the appendix material in a \textsf{biblatex} |refsection|
412 % environment and emits the appendix bibliography with
413 % |\printbibliography|. In this mode the user is responsible for
414 % loading \textsf{biblatex} and declaring bibliography resources with
415 % |\addbibresource| in the preamble; resources are shared between the
416 % main document and the appendix |refsection|, but citations and the
417 % printed bibliography are scoped independently. The |bibengine| option
418 % only has an effect when |bibliography=separate|.
419 % (By default this option is set to |separate|.)
420 % \subsection{Mode}
421 % \DescribeOption{appendix}
422 % An optional \meta{mode} can be specified when loading the package:
423 % \begin{quote}|\usepackage[appendix=|\meta{mode}|]{apxproof}|\end{quote}
424 % \meta{mode} can take one of the following four values:
425 % \begin{description}
426 % \item[|append|] This is the default.
427 % Appendix material gathered by \textsf{apxproof} is appended to
428 % the main text.
429 % \item[|inline|] In this mode, \textsf{apxproof} simply inlines the
430 % content along with the main text.
431 % \item[|strip|] This mode functions similarly to |append| except that
432 % the appendix is not appended at the end of the document. All appendix
433 % material is therefore removed.
434 % \item[|chapterend|] In this mode, appendix material for each chapter
435 % is gathered separately and emitted at the end of that chapter
436 % (i.e., just before the next |\chapter|, |\part|, |\frontmatter|,
437 % |\mainmatter|, or |\backmatter| command, or at the end of the
438 % document), using the |subappendices| environment from the
439 % \textsf{appendix} package. Only |bibliography=common| is supported
440 % in this mode. See Section~\ref{sec:customization} for the
441 % |\chapterappendixprelim| and |\flushchapterappendix| customization
442 % macros.
443 % \end{description}
444 %
445 % \subsection{Customization}
446 % \label{sec:customization}
447 % \textsf{apxproof} provides a few macros that can be redefined (using
448 % |\renewcommand|) to customize the appearance of the appendix:
449 % \begin{description}
450 % \item[\textbackslash|mainbodyrepeatedtheorem|]\DescribeMacro{\mainbodyrepeatedtheorem}
451 % is a macro that is executed at the beginning of the body of every
452 % repeated theorem. This can be used to notify the reader that the
453 % theorem is repeated in appendix in some way, e.g., with a margin note.
454 % \item[\textbackslash|appendixsectionformat|\marg{number}\marg{title}]\DescribeMacro{\appendixsectionformat} is a macro
455 % that indicates how to format the section titles in the Appendix, given
456 % the number and title of the section in the main text. By
457 % default, they appear as ``Proofs for Section~\meta{number}
458 % (\meta{title})''.
459 % \item[\textbackslash|appendixproofname|\marg{type}\marg{ref}]\DescribeMacro{\appendixproofname}
460 % is a macro that determines the title of a proof deferred to the
461 % appendix when it follows a |\newtheoremrep| or |\newtheoremrep*|
462 % environment. By default, this macro is empty, which means proofs are
463 % titled ``Proof.'' as usual. When redefined to a non-empty value, the
464 % expansion is used as the title of the appendix proof; \meta{type} is
465 % the title of the theorem environment (e.g., |Theorem|) and \meta{ref}
466 % is a reference to the theorem statement in the main text. To title
467 % all such proofs ``Proof of \meta{type}~\meta{number}'', one would
468 % typically write:
469 % \begin{quote}
470 % \begin{verbatim}
471 % \renewcommand{\appendixproofname}[2]{Proof of #1~#2}
472 % \end{verbatim}
473 % \end{quote}
474 % This hook applies whether the theorem is restated in the appendix
475 % (|\newtheoremrep|) or not (|\newtheoremrep*|). It has no effect on
476 % manually written |appendixproof| environments or on proofs given an
477 % explicit optional title.
478 % \item[\textbackslash|appendixrefname|]\DescribeMacro{\appendixrefname} contains the heading that is displayed before
479 % the bibliography. By default, this is ``References for the
480 % Appendix''. (Note that this command is also defined and used by the
481 % |memoir| document class.)
482 % \item[\textbackslash|appendixbibliographystyle|]\DescribeMacro{\appendixbibliographystyle} contains the |.bst| bibliography
483 % style that is used in the bibliography in appendix. By default, this is
484 % |alpha|.
485 % \item[\textbackslash|appendixbibliographyprelim|]\DescribeMacro{\appendixbibliographyprelim} contains arbitrary code that is executed
486 % just before the production of the bibliography in appendix, which can
487 % be used to configure the way it is displayed.
488 % \item[\textbackslash|appendixprelim|]\DescribeMacro{\appendixprelim} contains arbitrary code that is executed
489 % just before the production of the appendix, which can
490 % be used to configure the way it is displayed. By default, this command
491 % contains |\clearpage\onecolumn| (the appendix is typeset on a new page
492 % in single-column mode) but redefining this option allows changing this
493 % behavior. This macro has no effect in |chapterend| mode; use
494 % |\chapterappendixprelim| instead.
495 % \item[\textbackslash|chapterappendixprelim|]\DescribeMacro{\chapterappendixprelim}
496 % (|chapterend| mode only) contains arbitrary code that is executed
497 % just before each chapter's appendix block. By default, this command
498 % contains |\clearpage| (each chapter appendix starts on a new page).
499 % This macro has no effect in |append| or |strip| mode; use
500 % |\appendixprelim| instead.
501 % \item[\textbackslash|flushchapterappendix|]\DescribeMacro{\flushchapterappendix}
502 % (|chapterend| mode only) manually emits the current chapter's
503 % accumulated appendix material at the point of invocation, and starts
504 % a fresh per-chapter buffer. The package automatically inserts an
505 % equivalent flush before each |\chapter|, |\part|, |\frontmatter|,
506 % |\mainmatter|, |\backmatter|, and at the end of the document, so
507 % this macro is only useful in unusual document structures where an
508 % appendix needs to be emitted at a location that is not a standard
509 % structural boundary.
510 % \end{description}
511 % \DescribeOption{repeqn}
512 % Another customization capability concerns \emph{numbered equations} that are present
513 % within repeated theorems. An optional |repeqn| option can be specified
514 % when loading the package, which controls whether
515 % equation numbers should be as in the main text (by setting this option
516 % to |same|, the default) or independently
517 % numbered (by setting this option to |independent|). In the latter case,
518 % whenever a referenceable counter is set with |\label{|\meta{counter}|}|,
519 % |\ref{|\meta{counter}|}| references the counter in the main text, while
520 % |\ref{|\meta{counter}|-apx}| references the counter in the appendix
521 % (except in |inline| mode, where both have the same effect).
522 %
523 % \DescribeOption{forwardlinking}
524 % Another customization option concerns hyperlinking.
525 % Usually, when \textsf{hyperref} is loaded, |foobarrep|
526 % environments in the main text have their number link to their repetition in the
527 % appendix. To suppress this behavior and have |foobarrep| environments
528 % treated as if \textsf{hyperref} were not loaded, one can specify the
529 % value |no| to the |forwardlinking| option when loading the package. (By
530 % default this option is set to |yes|.)
531 %
532 % \subsection{Advanced Features}
533 % We now describe a few advanced macros and environments, the usage of
534 % which is limited to special cases:
535 % \begin{description}
536 % \item[|nestedproof|]\DescribeEnv{nestedproof} is an environment that
537 % can be used within a |proof| environment deferred in the appendix; this
538 % is required because, for technical reasons, no |proof| environment can
539 % be nested within a deferred |proof| environment.
540 % \item[\textbackslash|noproofinappendix|]\DescribeMacro{\noproofinappendix}
541 % can be used inside repeated theorems that are not followed by a
542 % |proof| or |appendixproof| environment; the point is to ensure that a further
543 % |proof| environment cannot be mistakenly understood as a proof of the repeated
544 % theorem. It should not be needed in most situations as
545 % \textsf{apxproof} tries figuring out when a proof follows a repeated
546 % theorem automatically, but may occasionally be needed in complex
547 % scenarios.
548 % \item[\textbackslash|nosectionappendix|]\DescribeMacro{\nosectionappendix}
549 % is to be used inside a section that \emph{does} contain appendix material, but
550 % for which a section in the appendix should not be created. This should
551 % be rarely needed. When this command is present, appendix material is
552 % appended to the end of the previously created section.
553 % \end{description}
554 % \subsection{Grouping Appendix Material Under a Single Section}
555 % \changes{v1.4.0}{2026/05/14}{Documented workarounds for grouping
556 % per-section appendices under a single wrapping section. See \#56.}
557 % \label{sec:appendix-grouping}
558 % By default, \textsf{apxproof} produces one section in the appendix for
559 % each section of the main text that contains appendix material (with
560 % the format controlled by |\appendixsectionformat|). If you would
561 % rather have a single section in the appendix (e.g., titled
562 % ``Proofs'') with the per-section entries appearing as
563 % \emph{subsections} of that single section, two recipes are available.
564 %
565 % The first is fully explicit: disable the automatic per-section
566 % heading with |\nosectionappendix|, and write the desired structure
567 % directly inside |toappendix| environments.
568 % \begin{quote}
569 % \begin{verbatim}
570 % \begin{toappendix}
571 % \section{Proofs}
572 % \end{toappendix}
573 %
574 % \section{First}\label{sec:first}
575 % \nosectionappendix
576 % \begin{toappendix}
577 % \subsection{Proofs of Section~\ref{sec:first}}
578 % \end{toappendix}
579 %
580 % % ... theorems and proofs of section ``First'' ...
581 %
582 % \section{Second}\label{sec:second}
583 % \nosectionappendix
584 % \begin{toappendix}
585 % \subsection{Proofs of Section~\ref{sec:second}}
586 % \end{toappendix}
587 %
588 % % ... theorems and proofs of section ``Second'' ...
589 % \end{verbatim}
590 % \end{quote}
591 % The reader of the source can then see exactly what will be produced
592 % in the appendix, at the cost of some verbosity.
593 %
594 % The second recipe is more concise. The section level used by
595 % \textsf{apxproof} for the auto-generated appendix headings is swapped
596 % from |\section| to |\subsection| for the duration of an explicit
597 % |\begingroup|/|\endgroup| group:
598 % \begin{quote}
599 % \begin{verbatim}
600 % \begin{toappendix}
601 % \section{Proofs}
602 % \begingroup\makeatletter
603 % \let\axp@oldsection\subsection
604 % \makeatother
605 % \end{toappendix}
606 %
607 % \section{First}\label{sec:first}
608 % % ... theorems and proofs of section ``First'' ...
609 %
610 % \section{Second}\label{sec:second}
611 % % ... theorems and proofs of section ``Second'' ...
612 %
613 % \begin{toappendix}
614 % \endgroup
615 % \end{toappendix}
616 % \end{verbatim}
617 % \end{quote}
618 % The wrapping |\section{Proofs}| is written once, and every subsequent
619 % auto-generated appendix section heading is demoted to a |\subsection|
620 % for the scope of the group. The trade-off is that this recipe relies
621 % on an internal macro (|\axp@oldsection|) and on a manually balanced
622 % |\begingroup|/|\endgroup| pair across two separate |toappendix|
623 % environments.
624 % \section{Supported Document Classes}
625 % Because \textsf{apxproof} modifies sectioning commands, bibliographies,
626 % and proofs, it may not work straight away with arbitrary document classes.
627 % It has currently been tested with and is supported for the following
628 % document classes:
629 % \begin{itemize}
630 % \item \LaTeX{} standard document classes (e.g., |article.cls|)
631 % \item \href{https://www.ctan.org/pkg/koma-script}{KOMA-Script}
632 % (e.g., |scrartcl.cls|, |scrbook.cls|)
633 % \item \href{https://ctan.org/pkg/memoir}{|memoir.cls|}
634 % \item \href{https://www.acm.org/publications/proceedings-template}{ACM
635 % SIG Proceedings} (e.g., |sig-alternate.cls|, |acmart.cls|)
636 % \item \href{https://www.springer.com/computer/lncs/lncs+authors}{
637 % Springer's Lecture Notes in Computer Science} (e.g.,
638 % |llncs.cls|)
639 % \item
640 % \href{https://www.dagstuhl.de/en/publications/lipics}{Schlo\ss{}
641 % Dagstuhl's Leibniz International Proceedings in Informatics} (e.g.,
642 % |lipics.cls|, |lipcs-v2016.cls|)
643 % \end{itemize}
644 % Other classes may work out of the box. Adding support for specific
645 % classes is possible and can be requested from the
646 % author of this package.
647 % \section{Known Issues and Limitations}
648 % We report here some issues we are currently aware of:
649 % \begin{itemize}
650 % \item When using \textsf{hyperref}, the appendix in the bibliography is
651 % not hyperlinked. This is to avoid possible issues with multiply defined
652 % bibliography entries.
653 % \item |appendixproof|, |proof|, |toappendix| environments cannot be nested. This is a limitation of
654 % the \textsf{fancyvrb} package that \textsf{apxproof} relies on. Note
655 % the existence of the |nestedproof| environment for nested proofs.
656 % \item \textsf{apxproof} poorly interacts with Sync\TeX: identifying
657 % which source line has produced which box does not work for appendix
658 % content managed by \textsf{apxproof} or repeated theorems. No obvious
659 % fix is known, though this issue will be investigated in the long term.
660 % \item By default, when |bibliography=separate|, \textsf{apxproof}
661 % uses the \textsf{bibunits} package to generate a second bibliography.
662 % Packages incompatible with \textsf{bibunits} (notably
663 % \textsf{biblatex}) will therefore not work in that default
664 % configuration. For \textsf{biblatex} users, set |bibengine=biblatex|
665 % (in addition to |bibliography=separate|) to use \textsf{biblatex}'s
666 % own |refsection| machinery instead. The |bibliography=common| mode
667 % remains a third option that works with most bibliography packages.
668 % \end{itemize}
669 %
670 % Issues not listed here should be reported to the author.
671 %
672 % \section{License}
673 % Copyright \textcopyright{} 2016--2026 by Pierre Senellart.
674 %
675 % This work may be distributed and/or modified under the conditions of the
676 % \LaTeX{} Project Public License, either version 1.3 of this license or (at
677 % your option) any later version. The latest version of this license is in
678 % \url{http://www.latex-project.org/lppl.txt} and version 1.3 or later is part of
679 % all distributions of \LaTeX{} version 2005/12/01 or later.
680 %
681 % \section{Contact}
682 % \begin{itemize}
683 % \item \url{https://github.com/PierreSenellart/apxproof}
684 % \item
685 % Pierre Senellart
686 % \href{mailto:[email protected]}{<[email protected]>}
687 % \end{itemize}
688 % Bug reports and feature requests should
689 % preferably be submitted through the \emph{Issues} feature of GitHub.
690 %
691 % \section{Acknowledgments}
692 % Thanks to Antoine Amarilli for feedback and proofreading. Thanks to K.~D.
693 % Bauer for the implementation of the forward-linking mechanism, and
694 % for various bugfixes. Thanks to Leonid Kostrykin for an initial
695 % implementation of the |forwardlinking| option.
696 %
697 % \StopEventually{
698 % \PrintChanges
699 % \PrintIndex
700 % }
701 %
702 % \section{Implementation}
703 % We now describe the entire code of the package, in a literate programming
704 % fashion. Throughout the package, we use the |axp@| prefix to identify
705 % local macros and environment names, which are not meant to be used by the final
706 % user.
707 % \subsection{Dependencies}
708 % We first load a few package dependencies:
709 % \begin{itemize}
710 % \item \textsf{environ} to easily define the repeated theorem
711 % environments.
712 % \begin{macrocode}
713 \RequirePackage{environ}
714 % \end{macrocode}
715 % \item \textsf{etoolbox} to define simple toggles.
716 % \begin{macrocode}
717 \RequirePackage{etoolbox}
718 % \end{macrocode}
719 % \item \textsf{fancyvrb} for the bulk of the work of exporting appendix
720 % material in an auxiliary file.
721 % \begin{macrocode}
722 \RequirePackage{fancyvrb}
723 % \end{macrocode}
724 % \item \textsf{ifthen} for easier comparison of character strings.
725 % \begin{macrocode}
726 \RequirePackage{ifthen}
727 % \end{macrocode}
728 % \item \textsf{kvoptions} to manage options passed to the package.
729 % \begin{macrocode}
730 \RequirePackage{kvoptions}
731 % \end{macrocode}
732 % \item \textsf{catchfile} to be able to check the content of files
733 % |\input| within appendix content.
734 % \begin{macrocode}
735 \RequirePackage{catchfile}
736 % \end{macrocode}
737 % \item \textsf{amsthm} for its |\newteorem| macro.
738 % Some document classes (e.g., \textsf{lipics})
739 % preload \textsf{amsthm}: this is fine, |\RequirePackage{amsthm}|
740 % will simply have no effect. On the other hand, some other document
741 % classes (e.g., \textsf{llncs} or \textsf{sig-alternate}) define a
742 % |proof| environment that conflicts with \textsf{amsthm}, so we have to
743 % undefine this environment before loading \textsf{amsthm}. In that case,
744 % we reestablish the existing proof environments, in case they had been
745 % customized (e.g., \textsf{sig-alternate})
746 % \changes{v1.0.4}{2017/03/08}{Re-establish custom proof environments}
747 % \begin{macrocode}
748 \@ifpackageloaded{amsthm}{
749 }{
750 \let\apx@oldamsthmproof\proof
751 \let\apx@oldamsthmendproof\endproof
752 \let\proof\undefined
753 \let\endproof\undefined
754 }
755 \RequirePackage{amsthm}
756 \ifdefined\apx@oldamsthmproof
757 \let\proof\apx@oldamsthmproof
758 \let\endproof\apx@oldamsthmendproof
759 \fi
760 % \end{macrocode}
761 % \end{itemize}
762 % \subsection{Option Processing}
763 % Many names throughout the package use an arobase (|@|) to avoid name
764 % conflict with user-defined names. To simplify the compilation of the
765 % documentation, we simply make it a regular character in all the rest.
766 % \begin{macrocode}
767 \makeatletter
768 % \end{macrocode}
769 % We setup the processing of options using \textsf{keyval} facilities.
770 % \begin{macrocode}
771 \SetupKeyvalOptions{
772 family=axp,
773 prefix=axp@
774 }
775 % \end{macrocode}
776 % We declare the following options:
777 % \begin{itemize}
778 % \item |appendix|, with a default value of |append| (other possible
779 % values: |strip|, |inline|);
780 % \item |bibliography|, with a default value of |separate| (other
781 % possible value: |common|);
782 % \item |repeqn|, with a default value of |same| (other possible value:
783 % |independent|).
784 % \end{itemize}
785 % \begin{macro}{\axp@appendix}
786 % \begin{macrocode}
787 \DeclareStringOption[append]{appendix}
788 % \end{macrocode}
789 % \end{macro}
790 % \begin{macro}{\axp@bibliography}
791 % \changes{v1.0.4}{2017/03/02}{\texttt{bibliography} option}
792 % \begin{macrocode}
793 \DeclareStringOption[separate]{bibliography}
794 % \end{macrocode}
795 % \end{macro}
796 % \begin{macro}{\axp@bibengine}
797 % \changes{v1.4.0}{2026/05/14}{\texttt{bibengine} option to select
798 % the engine used for separate bibliographies: \textsf{bibunits}
799 % (default) or \textsf{biblatex}. See \#29.}
800 % \begin{macrocode}
801 \DeclareStringOption[bibtex]{bibengine}
802 % \end{macrocode}
803 % \end{macro}
804 % \begin{macro}{\axp@repeqn}
805 % \changes{v1.1.0}{2018/07/20}{\texttt{repeqn} option}
806 % \begin{macrocode}
807 \DeclareStringOption[same]{repeqn}
808 % \end{macrocode}
809 % \end{macro}
810 % \begin{macro}{\axp@forwardlinking}
811 % \changes{v1.2.3}{2021/07/12}{\texttt{forwardlinking} option}
812 % \begin{macrocode}
813 \DeclareStringOption[yes]{forwardlinking}
814 % \end{macrocode}
815 % \end{macro}
816 % \begin{macrocode}
817 \ProcessLocalKeyvalOptions*
818 % \end{macrocode}
819 % We check that the value of the options are valid, and add a
820 % message to the compilation log.
821 % \begin{macrocode}
822 \ifthenelse{\equal{\axp@appendix}{append}}{
823 \message{apxproof: Appendix material appended to the document}
824 }{\ifthenelse{\equal{\axp@appendix}{strip}}{
825 \message{apxproof: Appendix material stripped}
826 }{\ifthenelse{\equal{\axp@appendix}{inline}}{
827 \message{apxproof: Appendix material inlined within the document}
828 }{\ifthenelse{\equal{\axp@appendix}{chapterend}}{
829 \message{apxproof: Appendix material appended at the end of each chapter}
830 }{
831 \errmessage{Error: unsupported option appendix=\axp@appendix\ for
832 package apxproof}
833 }}}}
834 \ifthenelse{\equal{\axp@bibengine}{bibtex}}{
835 }{\ifthenelse{\equal{\axp@bibengine}{biblatex}}{
836 }{
837 \errmessage{Error: unsupported option bibengine=\axp@bibengine\ for
838 package apxproof}
839 }}
840 \ifthenelse{\equal{\axp@bibliography}{separate}}{
841 % \end{macrocode}
842 % In |bibengine=bibtex| mode (the default), the external
843 % \textsf{bibunits} package is used to add a second bibliography for
844 % the appendix material. In |bibengine=biblatex| mode, no extra
845 % package is loaded here: \textsf{biblatex} is expected to have been
846 % loaded by the user, and its |refsection| environment is used at
847 % appendix typeset time to scope citations.
848 % \changes{v1.2.0}{2019/04/17}{Do not load \textsf{bibunits} if
849 % \texttt{bibliography} is set to \texttt{common}}
850 % \begin{macrocode}
851 \ifthenelse{\equal{\axp@bibengine}{bibtex}}{
852 \RequirePackage{bibunits}
853 \message{apxproof: Separate bibliography for appendix material (bibunits)}
854 }{
855 \message{apxproof: Separate bibliography for appendix material (biblatex)}
856 }
857 }{\ifthenelse{\equal{\axp@bibliography}{common}}{
858 \message{apxproof: Common bibliography for appendix and main text}
859 }{
860 \errmessage{Error: unsupported option bibliography=\axp@bibliography\ for
861 package apxproof}
862 }}
863 \ifthenelse{\equal{\axp@appendix}{chapterend}
864 \AND\equal{\axp@bibliography}{separate}}{
865 \PackageError{apxproof}{%
866 bibliography=separate is not supported with appendix=chapterend}{%
867 Use bibliography=common instead.}
868 }{}
869 \ifthenelse{\equal{\axp@repeqn}{same}}{
870 \message{apxproof: Repeated equations keep the same numbering}
871 }{\ifthenelse{\equal{\axp@repeqn}{independent}}{
872 \message{apxproof: Repeated equations are independently numbered}
873 }{
874 \errmessage{Error: unsupported option repeqn=\axp@repeqn\ for
875 package apxproof}
876 }}
877 % \end{macrocode}
878 % \begin{macro}{\axp@forward@suppress}
879 % \begin{macrocode}
880 \newbool{axp@forward@suppress}
881 \ifthenelse{\equal{\axp@forwardlinking}{yes}}{
882 }{\ifthenelse{\equal{\axp@forwardlinking}{no}}{
883 \message{apxproof: Disable forward linking}
884 \global\booltrue{axp@forward@suppress}%
885 }{
886 \errmessage{Error: unsupported option forwardlinking=\axp@repeqn\ for
887 package apxproof}
888 }}
889 % \end{macrocode}
890 % \end{macro}
891 % \subsection{Macros Common to All Compilation Modes}
892 % \begin{macro}{\axp@newtheoremrep@definetheorem}
893 % \changes{v1.2.0}{2019/10/01}{Restore predefined theorem counters}
894 % \changes{v1.2.6}{2025/08/04}{Undefine counter printing command to
895 % avoid warning}
896 % Common to all compilation modes, we define
897 % |\axp@newtheoremrep@definetheorem|.
898 % When called with first argument |foobar|, we first undefine the existing
899 % |foobar| environment (and its counter) if it has already been defined (e.g., by the
900 % document class), then invoke |\axp@newtheorem| for the regular version
901 % of the theorem |foobar|, saving and restoring any existing theorem counter unless the
902 % |\newtheoremdep| redefines the base counter.
903 % \begin{macrocode}
904 \def\axp@newtheoremrep@definetheorem#1#2#3#4{%
905 \expandafter\let\csname #1\endcsname\undefined
906 \expandafter\let\csname the#1\endcsname\undefined
907 \ifcsname c@#1\endcsname
908 \expandafter\expandafter\expandafter\let\expandafter\expandafter
909 \csname c@axp@#1\endcsname\csname c@#1\endcsname
910 \expandafter\let\csname c@#1\endcsname\undefined
911 \fi
912 \axp@newtheorem{#1}{#2}{#3}{#4}%
913 \ifcsname c@axp@#1\endcsname
914 \ifx\relax#2\relax
915 \expandafter\expandafter\expandafter\let\expandafter\expandafter
916 \csname c@#1\endcsname\csname c@axp@#1\endcsname
917 \else
918 \fi
919 \fi
920 }
921 % \end{macrocode}
922 % \end{macro}
923 % \begin{macro}{\axp@newtheorem}
924 % \changes{v1.0.6}{2018/05/10}{Introduce intermediary command for theorem
925 % macro}
926 % \begin{macro}{\@axp@newtheorem}
927 % \begin{macro}{\@@axp@newtheorem}
928 % We introduce an intermediate |\axp@newtheorem| command to define a new
929 % theorem, differently depending on whether there is a section counter or
930 % not. This will be useful, in particular to allow changing this
931 % definition depending on the document class. This command uses two
932 % intermediary commands, |\@axp@newtheorem| and |\@@axp@newtheorem|, for
933 % the non-starred and starred versions.
934 % \begin{macrocode}
935 \def\axp@newtheorem{\@ifstar\@@axp@newtheorem\@axp@newtheorem}
936 \def\@axp@newtheorem#1#2#3#4{%
937 \ifx\relax#4\relax
938 \newtheorem{#1}[#2]{#3}%
939 \else
940 \newtheorem{#1}{#3}[#4]%
941 \fi
942 }
943 \def\@@axp@newtheorem#1#2{%
944 \newtheorem*{#1}{#2}%
945 }
946 % \end{macrocode}
947 % \end{macro}
948 % \end{macro}
949 % \end{macro}
950 % \begin{macro}{\newtheoremrep}
951 % \begin{macro}{\axp@newtheoremreptmp}
952 % We define the high-level |\newtheoremrep| to have the same syntax as
953 % \textsf{amsthm}'s |\newtheorem|, plus an optional |*| variant that
954 % defers the proof to the appendix without restating the theorem.
955 % For this purpose, we need a little
956 % trick to deal with the second and fourth optional arguments, which is what
957 % |\@oparg| and |\axp@newtheoremreptmp| are
958 % used for. |\axp@newtheoremrep| is defined differently
959 % depending on the compilation mode.
960 % \changes{v1.4.0}{2026/05/14}{Added starred form of \cs{newtheoremrep}
961 % for proof-deferred theorems that are not restated in the appendix}
962 % \begin{macrocode}
963 \newcommand\newtheoremrep{%
964 \@ifstar{\axp@newtheoremrep@star}{\axp@newtheoremrep@nostar}%
965 }
966 \newcommand\axp@newtheoremrep@star[1]{%
967 \global\csdef{axp@proofof@#1}{}%
968 \@oparg{\axp@newtheoremreptmp{#1}}[]%
969 }
970 \newcommand\axp@newtheoremrep@nostar[1]{%
971 \global\csundef{axp@proofof@#1}%
972 \@oparg{\axp@newtheoremreptmp{#1}}[]%
973 }
974 \def\axp@newtheoremreptmp#1[#2]#3{%
975 \@oparg{\axp@newtheoremrep{#1}[#2]{#3}}[]%
976 }
977 % \end{macrocode}
978 % \end{macro}
979 % \end{macro}
980 % \begin{environment}{proofsketch}
981 % Simple |proofsketch| environment.
982 % \changes{v1.0.3}{2016/12/16}{Ignore spaces after beginning of Proof sketch}
983 % \begin{macrocode}
984 \newenvironment{proofsketch}{\begin{axp@oldproof}[Proof sketch]}{\end{axp@oldproof}}
985 % \end{macrocode}
986 % \end{environment}
987 % \begin{macro}{\mainbodyrepeatedtheorem}
988 % \changes{v1.2.0}{2019/09/21}{Configurable repeated theorem command}
989 % \begin{macro}{\appendixrefname}
990 % \changes{v1.2.1}{2020/10/09}{Fix compatibility with
991 % \texttt{memoir} document class}
992 % \begin{macro}{\appendixbibliographystyle}
993 % \begin{macro}{\appendixbibliographyprelim}
994 % \begin{macro}{\appendixprelim}
995 % \changes{v1.0.4}{2017/03/03}{Configurable appendix style}
996 % \begin{macro}{\appendixsectionformat}
997 % \changes{v1.1.0}{2018/07/17}{Fix missing space in default
998 % \cs{appendixsectionformat}}
999 % \begin{macro}{\appendixproofname}
1000 % \changes{v1.4.0}{2026/05/14}{Added \cs{appendixproofname} hook for
1001 % customizing the title of a proof deferred to the appendix}
1002 % We provide sensible defaults for these user-customizable macros.
1003 % Even though they are not all useful in all modes, we define them for
1004 % all modes so that a |\renewcommand| works in all cases.
1005 % \begin{macrocode}
1006 \newcommand{\mainbodyrepeatedtheorem}{}
1007 \providecommand{\appendixrefname}{References for the Appendix}
1008 \newcommand{\appendixbibliographystyle}{alpha}
1009 \newcommand{\appendixbibliographyprelim}{}
1010 \newcommand{\appendixprelim}{\clearpage\onecolumn}
1011 \newcommand{\appendixsectionformat}[2]{Proofs for Section~#1\ (#2)}
1012 \newcommand{\appendixproofname}[2]{}
1013 % \end{macrocode}
1014 % \end{macro}
1015 % \end{macro}
1016 % \end{macro}
1017 % \end{macro}
1018 % \end{macro}
1019 % \end{macro}
1020 % \end{macro}
1021 % \begin{environment}{axp@oldproof}
1022 % We save the definition of the existing |proof| environment.
1023 % \begin{macrocode}
1024 \let\axp@oldproof\proof
1025 \let\endaxp@oldproof\endproof
1026 % \end{macrocode}
1027 % \end{environment}
1028 % We define a utility macro that will be used to properly set the
1029 % |\label| command (and its \textsf{amsmath} counterpart,
1030 % |\label@in@display|) for equations within repeated theorems, depending on the
1031 % compilation mode.
1032 % \begin{macro}{\axp@redefinelabels}
1033 % \changes{v1.1.0}{2018/07/04}{Fix \cs{label} not being disabled
1034 % in \textsf{amsmath} environments, where \cs{label@in@display} is
1035 % used instead (K. D. Bauer)}
1036 % \changes{v1.2.0}{2019/02/15}{Fix extra spacing erroneously
1037 % introduced within the \texttt{\textbackslash axp@redefinelabels}
1038 % macro}
1039 % \begin{macrocode}
1040 \newcommand{\axp@redefinelabels}{%
1041 \providecommand\label@in@display{}%
1042 \ifthenelse{\equal{\axp@appendix}{inline}}{%
1043 \let\axp@oldlabel\label
1044 \let\axp@oldlabel@in@display\label@in@display
1045 \renewcommand\label[1]{%
1046 \axp@oldlabel{##1}%
1047 \axp@oldlabel{##1-apx}%
1048 }%
1049 \renewcommand\label@in@display[1]{%
1050 \axp@oldlabel@in@display{##1}%
1051 \axp@oldlabel{##1-apx}%
1052 }%
1053 }{%
1054 \let\axp@oldlabel\label
1055 \let\axp@oldlabel@in@display\label@in@display
1056 \renewcommand\label[1]{\axp@oldlabel{##1-apx}}%
1057 \renewcommand\label@in@display[1]{\axp@oldlabel@in@display{##1-apx}}%
1058 }%
1059 }
1060 % \end{macrocode}
1061 % \end{macro}
1062 % \subsubsection{Class-Specific Behavior}
1063 % Finally, some class-specific behavior common to all compilation modes.
1064 % \paragraph{\textsf{llncs} and other Springer document classes}
1065 % \changes{v1.0.6}{2018/05/10}{Better support of Springer document
1066 % classes}
1067 % \begin{macrocode}
1068 \ifdefined\spnewtheorem
1069 % \end{macrocode}
1070 % \begin{macro}{\@axp@newtheorem}
1071 % \begin{macro}{\@@axp@newtheorem}
1072 % It is necessary to use |\spnewtheorem| instead of |\newtheorem| in
1073 % Springer document classes to obtain standard formatting.
1074 % \begin{macrocode}
1075 \def\@axp@newtheorem#1#2#3#4{%
1076 \ifx\relax#4\relax
1077 \ifx\relax#2\relax
1078 \spnewtheorem{#1}{#3}{\bfseries}{\itshape}%
1079 \else
1080 \spnewtheorem{#1}[#2]{#3}{\bfseries}{\itshape}%
1081 \fi
1082 \else
1083 \spnewtheorem{#1}{#3}[#4]{\bfseries}{\itshape}%
1084 \fi
1085 }
1086 \def\@@axp@newtheorem#1#2{%
1087 \spnewtheorem*{#1}{#2}{\upshape\bfseries}{\itshape}%
1088 }
1089 % \end{macrocode}
1090 % \end{macro}
1091 % \end{macro}
1092 % \begin{macro}{proofsketch}
1093 % \changes{v1.2.0}{2019/02/15}{Fix proof sketches in inline
1094 % compilation mode for Springer document classes}
1095 % We redefine the |proofsketch| environment, which is used
1096 % differently in the base class.
1097 % \begin{macrocode}
1098 \renewenvironment{proofsketch}{\begin{axp@oldproof}[sketch]}{\end{axp@oldproof}}
1099 % \end{macrocode}
1100 % \end{macro}
1101 % We have to redefine the macro |\@thmcountersep| for proper sectioned
1102 % counters.
1103 % \begin{macrocode}
1104 \def\@thmcountersep{.}
1105 \fi
1106 % \end{macrocode}
1107 % \paragraph{\textsf{acmart}}
1108 % \changes{v1.2.6}{2025/09/29}{Fix compilation issues in recent versions of \textsf{acmart}}
1109 % Some versions of \textsf{acmart} define a |\ACM@origsection| macro and
1110 % verify that |\section| has the same content. We need to update
1111 % |\ACM@origsection| accordingly.
1112 % \begin{macrocode}
1113 \ifdefined\ACM@origsection
1114 \AtBeginDocument{\let\ACM@origsection\section}
1115 \fi
1116 % \end{macrocode}
1117 % \subsection{Inline Compilation Mode}
1118 % \begin{macrocode}
1119 \ifthenelse{\equal{\axp@appendix}{inline}}{
1120 % \end{macrocode}
1121 % \begin{macro}{\axp@newtheoremrep}
1122 % In inline mode, |\axp@newtheoremrep| uses
1123 % |\axp@newtheoremrep@definetheorem| to define the regular theorem
1124 % environment and creates a repeated theorem
1125 % environment that behaves exactly as the regular theorem environment,
1126 % while calling |\axp@redefinelabels| to make sure that |-axp| variants
1127 % of equation counters are defined.
1128 % \changes{v1.2.0}{2019/02/15}{Fix formatting of theorems without
1129 % notes in some document classes in inline mode}
1130 % \begin{macrocode}
1131 \def\axp@newtheoremrep#1[#2]#3[#4]{%
1132 \axp@newtheoremrep@definetheorem{#1}{#2}{#3}{#4}%
1133 \NewEnviron{#1rep}[1][]{%
1134 \ifx\relax##1\relax
1135 \begin{#1}\axp@redefinelabels\BODY\end{#1}%
1136 \else
1137 \begin{#1}[##1]\axp@redefinelabels\BODY\end{#1}%
1138 \fi
1139 }
1140 }
1141 % \end{macrocode}
1142 % \end{macro}
1143 % \begin{environment}{inlineproof}
1144 % \begin{environment}{nestedproof}
1145 % \begin{environment}{appendixproof}
1146 % In inline mode, these environments behave like the regular |proof|
1147 % environment.
1148 % \begin{macrocode}
1149 \let\inlineproof\proof
1150 \let\endinlineproof\endproof
1151 \let\nestedproof\proof
1152 \let\endnestedproof\endproof
1153 \let\appendixproof\proof
1154 \let\endappendixproof\endproof
1155 % \end{macrocode}
1156 % \end{environment}
1157 % \end{environment}
1158 % \end{environment}
1159 % \begin{environment}{toappendix}
1160 % \begin{macro}{\noproofinappendix}
1161 % \begin{macro}{\nosectionappendix}
1162 % In inline mode, this environment and these macros are no-ops.
1163 % \begin{macrocode}
1164 \newenvironment{toappendix}{}{}
1165 \let\noproofinappendix\relax
1166 \let\nosectionappendix\relax
1167 % \end{macrocode}
1168 % \end{macro}
1169 % \end{macro}
1170 % \end{environment}
1171 % \begin{macrocode}
1172 }
1173 % \end{macrocode}
1174 % \subsection{Append, Strip, or Chapter End Compilation Modes}
1175 % \begin{macrocode}
1176 {
1177 % \end{macrocode}
1178 % We now deal with the case where \textsf{apxproof} really does something
1179 % useful: either append the appendix material to the document, or strip
1180 % it entirely.
1181 % \bigskip
1182 % \subsubsection{Auxiliary File for the Appendix}
1183 % \begin{macro}{\axp@proofsfile}
1184 % We open a new auxiliary file, with extension |.axp|, where the appendix
1185 % material will be dumped.
1186 % \changes{v1.1.0}{2018/07/11}{Initialization deferred to \cs{AtBeginDocument}
1187 % for compatibility with \cs{dump}ed precompiled preambles (K. D.
1188 % Bauer)}
1189 % \begin{macrocode}
1190 \AtBeginDocument{
1191 \newwrite\axp@proofsfile
1192 \ifthenelse{\equal{\axp@appendix}{chapterend}}{%
1193 \axp@openchapterfile
1194 }{%
1195 \immediate\openout\axp@proofsfile=\jobname.axp
1196 }%
1197 }
1198 % \end{macrocode}
1199 % \end{macro}
1200 % \begin{environment}{proof}
1201 % \begin{macro}{\section}
1202 % At the beginning of this file, we make |@| a regular character (since
1203 % it will be used in several places for internal names) and reestablish the original definition of
1204 % the |proof| environment and the |\section| macro.
1205 % \begin{macrocode}
1206 \newcommand{\axp@writeproofsfilepreamble}{%
1207 \immediate\write\axp@proofsfile{%
1208 \noexpand\makeatletter
1209 \noexpand\let\noexpand\proof\noexpand\axp@oldproof
1210 \noexpand\let\noexpand\endproof\noexpand\endaxp@oldproof
1211 \noexpand\let\noexpand\claimproof\noexpand\axp@oldclaimproof
1212 \noexpand\let\noexpand\endclaimproof\noexpand\endaxp@oldclaimproof
1213 \noexpand\let\noexpand\section\noexpand\axp@oldsection
1214 }%
1215 }
1216 \AtBeginDocument{
1217 \ifthenelse{\equal{\axp@appendix}{chapterend}}{}{%
1218 \axp@writeproofsfilepreamble
1219 }%
1220 }
1221 % \end{macrocode}
1222 % \end{macro}
1223 % \end{environment}
1224 % \begin{macro}{\axp@unactivateeightbit}
1225 % \changes{v1.1.0}{2019/01/28}{Fix compilation of non-ASCII
1226 % characters with \texttt{\textbackslash usepackage[utf8]\{inputenc\}}}
1227 % We need an auxiliary macro to disable active characters that have the
1228 % high bit set when writing to the |.axp| file. See
1229 % \url{https://tex.stackexchange.com/a/145361/166858}
1230 % \begin{macrocode}
1231 \def\axp@unactivateeightbit{%
1232 \count@=128%
1233 \loop
1234 \catcode\count@=12%
1235 \ifnum\count@<255%
1236 \advance\count@\@ne
1237 \repeat}
1238 % \end{macrocode}
1239 % \end{macro}
1240 % \begin{environment}{axp@VerbatimOut}
1241 % \begin{macro}{\FVB@axp@VerbatimOut}
1242 % \begin{macro}{\FVE@axp@VerbatimOut}
1243 % \changes{v1.1.0}{2018/10/02}{Make \textsf{apxproof} compatible with
1244 % independent use of \textsf{fancyvrb}}
1245 % Using the functionalities of the \textsf{fancyvrb} package, we define a
1246 % custom verbatim environment |axp@VerbatimOut| that writes every line
1247 % to the |\axp@proofsfile|. We also use the previous macro to disable active
1248 % characters with the eighth bit set, and we make sure the catcode of |@|
1249 % is reset for every verbatim environment, in case it is used by the user (e.g.,
1250 % as in the \textsf{xypic} package). Finally, as an additional
1251 % precaution, we reset |\FV@CatCodesHook| that is for example set by the
1252 % |commandchars| or |commentchar| option of |\fvset|.
1253 % \changes{v1.2.1}{2020/01/01}{Fix compatibility with
1254 % \textsf{xypic} package}
1255 % \changes{v1.2.1}{2020/10/15}{Fix compatibility with other uses of \textsf{fancyvrb} that set
1256 % \texttt{\textbackslash FV@CatCodesHook}}
1257 % \begin{macrocode}
1258 \DefineVerbatimEnvironment{axp@VerbatimOut}{axp@VerbatimOut}{}
1259 \def\FVB@axp@VerbatimOut{%
1260 \@bsphack
1261 \begingroup
1262 \axp@unactivateeightbit
1263 \FV@DefineWhiteSpace
1264 \def\FV@Space{\space}%
1265 \FV@DefineTabOut
1266 \def\FV@ProcessLine{\immediate\write\axp@proofsfile}%
1267 \let\FV@FontScanPrep\relax
1268 \let\@noligs\relax
1269 \def\FV@CatCodesHook{}%
1270 \FV@Scan}
1271 \def\FVE@axp@VerbatimOut{%
1272 \immediate\write\axp@proofsfile{\noexpand\makeatletter}%
1273 \endgroup\@esphack}
1274 % \end{macrocode}
1275 % \end{macro}
1276 % \end{macro}
1277 % \end{environment}
1278 % \begin{macro}{\axp@markchapterhasappendix}
1279 % No-op by default; overridden in |chapterend| mode to set a flag
1280 % indicating that the current chapter has appendix content.
1281 % \begin{macrocode}
1282 \newcommand{\axp@markchapterhasappendix}{}
1283 % \end{macrocode}
1284 % \end{macro}
1285 % \begin{environment}{toappendix}
1286 % The entire content of this environment is put in appendix,
1287 % starting a new appendix section beforehand if needed.
1288 % \begin{macrocode}
1289 \newenvironment{toappendix}
1290 {\axp@markchapterhasappendix\axp@writesection\axp@VerbatimOut}
1291 {\endaxp@VerbatimOut}
1292 % \end{macrocode}
1293 % \end{environment}
1294 % \subsubsection{Definition of New Theorems}
1295 % \begin{macro}{axp@seenreptheorem}
1296 % Used to indicate whether a repeated theorem was just typeset, without
1297 % its proof.
1298 % \begin{macrocode}
1299 \newtoggle{axp@seenreptheorem}
1300 % \end{macrocode}
1301 % \end{macro}
1302 % \begin{macro}{axp@rpcounter}
1303 % Sequentially incremented for every repeated theorem, used to create labels.
1304 % \begin{macrocode}
1305 \newcounter{axp@rpcounter}
1306 % \end{macrocode}
1307 % \end{macro}
1308 % \begin{macro}{axp@equation}
1309 % \begin{macro}{axp@equationx}
1310 % Used to save the value of the |equation| counter, when |repeqn| is set
1311 % to |same|.
1312 % \begin{macrocode}
1313 \newcounter{axp@equation}
1314 \newcounter{axp@equationx}
1315 % \end{macrocode}
1316 % \end{macro}
1317 % \end{macro}
1318 % \begin{macro}{axp@newtheoremrep}
1319 % With first argument |foobar|, we use
1320 % |\axp@newtheoremrep@definetheorem| to define the regular version of the
1321 % theorem |foobar|. We then patch |\begin{foobar}| so as not to
1322 % expect a proof in the appendix and define an internal theorem |axp@foobarrp| that
1323 % will be used in the appendix to restate the existing theorem.
1324 % In the starred mode, the theorem is not restated in the appendix,
1325 % so we do not define the |axp@foobarrp| environment.
1326 % \begin{macrocode}
1327 \def\axp@newtheoremrep#1[#2]#3[#4]{%
1328 \axp@newtheoremrep@definetheorem{#1}{#2}{#3}{#4}%
1329 \expandafter\pretocmd\csname #1\endcsname{\noproofinappendix}{}{}%
1330 \ifcsdef{axp@proofof@#1}{}{%
1331 \axp@newtheorem*{axp@#1rp}{#3}%
1332 }%
1333 \axp@forward@setup{#1}{#2}{#3}{#4}%
1334 % \end{macrocode}
1335 % We then define a |foobarrep| environment that increments the
1336 % |axp@rpcounter| and typeset the regular |foobar| theorem with a label
1337 % derived from the counter, along with a possible custom command to
1338 % identify repeated theorems. We distinguish the case when the theorem
1339 % argument has a note and when it does not.
1340 % \changes{v1.0.6}{2018/05/10}{Better handling of note-free theorems in
1341 % document classes that treat theorems differently when they have an
1342 % empty note}
1343 % We save the equation counter
1344 % before typesetting the theorem environment, to reset it to the same
1345 % value in the repeated environment when |repeqn| is set to |same|.
1346 % \changes{v1.2.2}{2020/11/25}{Fix handling of optional arguments of
1347 % repeated theorems containing optional arguments}
1348 % \begin{macrocode}
1349 \NewEnviron{#1rep}[1][]{%
1350 \ifthenelse{\equal{\axp@repeqn}{same}}{%
1351 \setcounter{axp@equation}{\value{equation}}%
1352 }{}%
1353 \addtocounter{axp@rpcounter}{1}%
1354 \ifx\relax##1\relax
1355 \axp@with@forward{#1}{\begin{#1}}\label{axp@r\roman{axp@rpcounter}}%
1356 \else
1357 \axp@with@forward{#1}{\begin{#1}[{##1}]}\label{axp@r\roman{axp@rpcounter}}%
1358 \fi
1359 \mainbodyrepeatedtheorem
1360 \BODY\end{#1}%
1361 % \end{macrocode}
1362 % We set the |axp@seenreptheorem| toggle to indicate that we are looking
1363 % for the proof of the theorem, then store in a macro the content of the
1364 % theorem's body.
1365 % \begin{macrocode}
1366 \global\toggletrue{axp@seenreptheorem}%
1367 \global\expandafter\let\csname rplet\roman{axp@rpcounter}%
1368 \endcsname
1369 \BODY
1370 % \end{macrocode}
1371 % Possibly after starting a new appendix section if needed, we typeset a
1372 % repeated version of the theorem using the |axp@foobarrp| environment
1373 % and a reference to the previously defined label.
1374 % We use |\axp@redefinelabels| in this environment to avoid multiply
1375 % defined labels. We have to deal in a careful way with theorem notes: we
1376 % want to use a theorem note to display the number of the repeated
1377 % theorem, but theorem notes are usually typeset in a much
1378 % different way (different font, parentheses) than theorem
1379 % headings. In the case of the Springer document
1380 % classes, we use the |\theopargself| macro to disable parentheses. For
1381 % other document classes, we need to manually patch the |\thmhead|
1382 % command at the right time. We also specially cover the case of
1383 % the ACM document class where |\@acmplainnotefont| is used instead
1384 % of |\thm@notefont|.
1385 % \changes{v1.0.2}{2016/12/13}{Fix missing space between repeated theorem
1386 % counter and theorem note}
1387 % \changes{v1.0.2}{2016/12/13}{Fix display of repeated theorem counter in
1388 % some document classes}
1389 % \changes{v1.0.6}{2018/05/10}{Fix incorrect use of \texttt{\textbackslash noexpand}
1390 % in optional argument of macro environment}
1391 % \changes{v1.2.0}{2019/10/07}{Fix display of theorem notes}
1392 % \begin{macrocode}
1393 \axp@markchapterhasappendix
1394 \axp@writesection%
1395 \immediate\write\axp@proofsfile{\noexpand\makeatletter}%
1396 \ifthenelse{\equal{\axp@repeqn}{same}}{%
1397 \immediate\write\axp@proofsfile{%
1398 \noexpand\setcounter{axp@equationx}{\value{equation}}%
1399 \noexpand\setcounter{equation}{\theaxp@equation}%
1400 }%
1401 }{}%
1402 \ifbool{axp@forward@suppress}{%
1403 \global\def\axp@refstar{\ref*}
1404 }{%
1405 \global\def\axp@refstar{\ref}
1406 }
1407 % \end{macrocode}
1408 % We write the auto-title state to the |.axp| file so that the following
1409 % deferred proof can title itself via |\appendixproofname|. In starred
1410 % mode, we also emit a forward-link target into the appendix so that
1411 % hyperlinks from the inline theorem number always land somewhere
1412 % defined, even if the user does not provide a proof.
1413 % \changes{v1.4.0}{2026/05/14}{Write auto-title state for
1414 % \cs{appendixproofname} hook}
1415 % \begin{macrocode}
1416 \immediate\write\axp@proofsfile{%
1417 \noexpand\gdef\noexpand\axp@nextproofof@type{#3}%
1418 \noexpand\gdef\noexpand\axp@nextproofof@label{axp@r\roman{axp@rpcounter}}%
1419 }%
1420 \ifcsdef{axp@proofof@#1}{%
1421 \immediate\write\axp@proofsfile{%
1422 \noexpand\axp@forward@target{axp@fw@r\roman{axp@rpcounter}}{}%
1423 }%
1424 }{%
1425 % \end{macrocode}
1426 % In the default (unstarred) mode, we emit the repeated version of the
1427 % theorem to the appendix; the forward-link target sits inside the
1428 % restated theorem. In starred mode, we skip this block entirely.
1429 % \begin{macrocode}
1430 \immediate\write\axp@proofsfile{{%
1431 \ifdefined\theopargself
1432 \noexpand\theopargself
1433 \else
1434 \noexpand\pretocmd{\noexpand\@begintheorem}{%
1435 \noexpand\patchcmd{\noexpand\thmhead}{\noexpand\@acmplainnotefont}{}{}{}%
1436 \noexpand\patchcmd{\noexpand\thmhead}{\noexpand\the\noexpand\thm@notefont}{}{}{}%
1437 \noexpand\patchcmd{\noexpand\thmhead}{(}{}{}{}%
1438 \noexpand\patchcmd{\noexpand\thmhead}{)}{}{}{}%
1439 }{}{}
1440 \fi
1441 \noexpand\begin{axp@#1rp}
1442 [%
1443 \noexpand\axp@refstar{axp@r\roman{axp@rpcounter}}%
1444 \@ifnotempty{##1}{%
1445 \ifdefined\theopargself
1446 \else
1447 \ifdefined\@acmplainnotefont
1448 \noexpand\@acmplainnotefont
1449 \else
1450 \noexpand\ifdefined\noexpand\thm@notefont
1451 \noexpand\the\noexpand\thm@notefont
1452 \noexpand\fi
1453 \fi
1454 \fi
1455 {} (\unexpanded{{##1}})%
1456 }%
1457 ]%
1458 \noexpand\axp@forward@target{axp@fw@r\roman{axp@rpcounter}}{}%
1459 \noexpand\axp@redefinelabels
1460 \expandafter\noexpand\csname rplet\roman{axp@rpcounter}%
1461 \endcsname
1462 \noexpand\end{axp@#1rp}
1463 }}%
1464 }%
1465 \ifthenelse{\equal{\axp@repeqn}{same}}{%
1466 \immediate\write\axp@proofsfile{%
1467 \noexpand\setcounter{equation}{\value{axp@equationx}}%
1468 }%
1469 }{}%
1470 }%
1471 }
1472 % \end{macrocode}
1473 % \end{macro}
1474 %
1475 % \subsubsection{Forward-Linking Mechanism}
1476 % \changes{v1.1.0}{2018/07/02}{Added forward-link mechanism (K. D. Bauer)}
1477 %
1478 % When hyperref is loaded, |foobarrep| environments
1479 % in the main text have their number link to their
1480 % repetition in the appendix.
1481 %
1482 %
1483
1484 %
1485 % \begin{macro}{\axp@with@forward}
1486 % In order to make the number of the |foobarrep| theorem a link
1487 % to its repeated version, we temporarily redefine the
1488 % |\thefoobar| command, or, if we inherited the counter
1489 % from a |bazbar| environment, the |\thebazbar| command.
1490 % This seems to be the only robust way to make the number
1491 % a |\hyperlink|, without adding extensive dependence
1492 % on internals of |amsthm|, the builtin |\newtheorem|
1493 % and possibly document-class specific definitions.
1494 %
1495 % In order to allow users to redefine |\thefoobar| without
1496 % breaking this feature, we redefine |\thefoobar| only
1497 % for the duration of the |\begin{foobar}| form,
1498 % resetting it to the old value as soon as possible.
1499 %
1500 % Redefining |\thefoobar| has the side effect of changing |\newlabel| entries
1501 % in the |.aux| file, so we need to to be able to disable
1502 % addition of the hyperlink, which is why we use an
1503 % intermediate |\axp@forward@link|\marg{target}\marg{text} macro,
1504 % We also redefine |\theHfoobar| which is used by |hyperref| but not
1505 % defined if |hyperref| was loaded after |\newtheoremrep| was used
1506 % and |\protect| it to output it verbatim into the |.aux| file.
1507 %
1508 % These hyperlinks are of course disabled in the |strip| compilation
1509 % mode.
1510 % \begin{macrocode}
1511 \newcommand{\axp@with@forward}[2]{%
1512 \ifthenelse{\equal{\axp@appendix}{strip}}{#2}{
1513 \global\booltrue{axp@forward}%
1514 \ifcsundef{axp@old@the\csname axp@cn@#1\endcsname}{%
1515 \csletcs{axp@old@the\csname axp@cn@#1\endcsname}{the\csname axp@cn@#1\endcsname}%
1516 \csletcs{theH\csname axp@cn@#1\endcsname}{the\csname axp@cn@#1\endcsname}%
1517 \csdef{the\csname axp@cn@#1\endcsname}{%
1518 \protect\axp@forward@link{axp@fw@r\roman{axp@rpcounter}}%
1519 {\csname axp@old@the\csname axp@cn@#1\endcsname\endcsname}%
1520 }%
1521 }{}%
1522 #2%
1523 \ifcsdef{axp@old@the\csname axp@cn@#1\endcsname}{%
1524 \csletcs{the\csname axp@cn@#1\endcsname}{axp@old@the\csname axp@cn@#1\endcsname}%
1525 }{}%
1526 \global\boolfalse{axp@forward}
1527 }}%
1528 % \end{macrocode}
1529 % \end{macro}
1530 %
1531 % \begin{macro}{\axp@forward@link}
1532 % \begin{macro}{axp@forward}
1533 % Dummy macro, for handling the unwanted change of
1534 % the |\newlabel| entry in the |.aux| file caused by
1535 % changing the definition of |\thefoobar|. We also use |\texorpdfstring|
1536 % to detect whether the reference appears within a PDF bookmark, in which
1537 % case we skip the test altogether.
1538 % \changes{v1.2.5}{2025/07/25}{Remove forward linking command from PDF bookmarks}
1539 %
1540 % \begin{macrocode}
1541 \newbool{axp@forward}
1542 \newcommand{\axp@forward@link}[2]{%
1543 \ifdefined\texorpdfstring\else\newcommand\texorpdfstring[2]{#2}\fi
1544 \texorpdfstring{%
1545 \ifboolexpr{ bool {axp@forward} and not bool {axp@forward@suppress} }{%
1546 \ifcsdef{hyperlink}{%
1547 \hyperlink{#1}{#2}%
1548 }{%
1549 #2%
1550 }%
1551 }{%
1552 #2%
1553 }%
1554 }{%
1555 #2%
1556 }%
1557 }%
1558 % \end{macrocode}
1559 % \end{macro}
1560 % \end{macro}
1561 %
1562 % \begin{macro}{\axp@forward@target}
1563 % Provides the needed |\hypertarget|.
1564 % Intended to be written to the |.axp| file.
1565 % \begin{macrocode}
1566 \newcommand{\axp@forward@target}[2]{%
1567 \ifcsname hypertarget\endcsname
1568 \hypertarget{#1}{#2}%
1569 \else
1570 #2%
1571 \fi
1572 }
1573 % \end{macrocode}
1574 % \end{macro}
1575 %
1576 % \begin{macro}{\axp@forward@setup}
1577 % \changes{v1.2.6}{2025/08/04}{Support for \texttt{aliascnt} counters}
1578 % In order to support counter inheritance with the first
1579 % optional argument of |\newtheoremrep|,
1580 % we need access to the name of the counter.
1581 % For compliance with the behavior of |\@axp@newtheorem|,
1582 % the first optional argument (|#2|) is ignored
1583 % if the second optional argument (|#4|) is given.
1584 % We also check whether |aliascnt| was used to define this counter;
1585 % if so, we use the original name as the counter name to handle
1586 % the way such aliases work.
1587 % \begin{macrocode}
1588 \newcommand{\axp@forward@setup}[4]{%
1589 \csedef{axp@cn@#1}{\ifblank{#4}{\ifblank{#2}{#1}{\ifcsdef{AC@cnt@#1}{#1}{#2}}}{#1}}%
1590 }
1591 % \end{macrocode}
1592 % \end{macro}
1593 %
1594 %
1595 % \subsubsection{Proof Environments}
1596 % \begin{macro}{\noproofinappendix}
1597 % Utility macro that toggles |axp@seenreptheorem| to false.
1598 % \begin{macrocode}
1599 \newcommand\noproofinappendix{%
1600 \global\togglefalse{axp@seenreptheorem}%
1601 }
1602 % \end{macrocode}
1603 % \end{macro}
1604 % \begin{macro}{\axp@apxproofstart}
1605 % \changes{v1.4.0}{2026/05/14}{Helper that consults \cs{appendixproofname}
1606 % at appendix typeset time to auto-title deferred proofs}
1607 % Helper invoked from the |.axp| file at appendix typeset time to open
1608 % a deferred proof. Reads the |\axp@nextproofof@*| state (set by the
1609 % preceding |theoremrep|) and consults |\appendixproofname| to decide
1610 % whether to pass an optional title argument.
1611 % \begin{macrocode}
1612 \gdef\axp@nextproofof@type{}
1613 \gdef\axp@nextproofof@label{}
1614 \def\axp@apxproofstart#1{%
1615 \protected@xdef\axp@apxproofstart@title{%
1616 \appendixproofname{\axp@nextproofof@type}%
1617 {\noexpand\ref{\axp@nextproofof@label}}%
1618 }%
1619 \ifx\axp@apxproofstart@title\@empty
1620 \begin{#1}%
1621 \else
1622 \expandafter\axp@apxproofstart@withtitle
1623 \expandafter{\axp@apxproofstart@title}{#1}%
1624 \fi
1625 }
1626 \def\axp@apxproofstart@withtitle#1#2{\begin{#2}[#1]}
1627 % \end{macrocode}
1628 % \end{macro}
1629 % \begin{environment}{appendixproof}
1630 % \changes{v1.2.4}{2021/11/03}{Support optional arguments in proofs}
1631 % We dump the content of this in appendix, within an original |proof|
1632 % environment, possibly after creating a new appendix section.
1633 % We support
1634 % optional arguments in proofs, but we need to be careful not to gobble
1635 % any newline character, that would make it impossible to process the
1636 % first line with \textsf{fancyvrb}.
1637 % \changes{v1.4.0}{2026/05/14}{Route deferred proofs through
1638 % \cs{axp@apxproofstart} to support \cs{appendixproofname}}
1639 % When the proof is auto-routed from a |theoremrep| (the toggle
1640 % |axp@seenreptheorem| is true at this point and no explicit optional
1641 % argument was given), we delegate the proof opening to
1642 % |\axp@apxproofstart| so that |\appendixproofname| is consulted at
1643 % appendix typeset time. A user-supplied optional argument or a manual
1644 % |\appendixproof| call (toggle false) bypasses this and uses
1645 % the standard ``Proof.'' heading.
1646 % \begin{macrocode}
1647 \def\appendixproof{\catcode`\^^M=\active\@ifnextchar[{\catcode`\^^M=5\@@appendixproof[axp@oldproof]}{\catcode`\^^M=5\@appendixproof[axp@oldproof]}}
1648 \def\@appendixproof[#1]%
1649 {%
1650 \axp@markchapterhasappendix
1651 \axp@writesection
1652 \iftoggle{axp@seenreptheorem}{%
1653 \immediate\write\axp@proofsfile{%
1654 \noexpand\makeatletter\noexpand\axp@apxproofstart{#1}\noexpand\makeatother%
1655 }%
1656 }{%
1657 \immediate\write\axp@proofsfile{%
1658 \noexpand\makeatletter\noexpand\begin{#1}\noexpand\makeatother%
1659 }%
1660 }%
1661 \axp@VerbatimOut
1662 }
1663 \def\@@appendixproof[#1][#2]%
1664 {%
1665 \axp@markchapterhasappendix
1666 \axp@writesection
1667 \immediate\write\axp@proofsfile{%
1668 \noexpand\makeatletter\noexpand\begin{#1}[\unexpanded{#2}]\noexpand\makeatother%
1669 }%
1670 \axp@VerbatimOut
1671 }
1672 \def\endappendixproof
1673 {%
1674 \endaxp@VerbatimOut
1675 \immediate\write\axp@proofsfile{%
1676 \noexpand\end{axp@oldproof}%
1677 }%
1678 \noproofinappendix
1679 }
1680 % \end{macrocode}
1681 % \end{environment}
1682 % \begin{environment}{proof}
1683 % This environment either puts the proof in appendix, if we are after a repeated
1684 % theorem without its proof, or inlines it otherwise. We support
1685 % optional arguments in proofs, but we need to be careful not to gobble
1686 % any newline character, that would make it impossible to process the
1687 % first line with \textsf{fancyvrb}.
1688 % \begin{macrocode}
1689 \def\proof{\catcode`\^^M=\active\ltx@ifnextchar@nospace[{\catcode`\^^M=5\axp@@proof}{\catcode`\^^M=5\axp@proof}}
1690 \def\axp@proof
1691 {%
1692 \iftoggle{axp@seenreptheorem}{%
1693 \appendixproof
1694 }{%
1695 \axp@oldproof
1696 }%
1697 }
1698 \def\axp@@proof[#1]%
1699 {%
1700 \iftoggle{axp@seenreptheorem}{%
1701 \appendixproof[#1]
1702 }{%
1703 \axp@oldproof[#1]
1704 }%
1705 }
1706 \def\endproof
1707 {%
1708 \iftoggle{axp@seenreptheorem}{%
1709 \endappendixproof
1710 }{%
1711 \endaxp@oldproof
1712 }%
1713 }
1714 % \end{macrocode}
1715 % \end{environment}
1716 % \begin{environment}{claimproof}
1717 % \changes{v1.2.4}{2021/11/03}{Support for \texttt{claimproof} environment
1718 % from \textsf{lipics}}
1719 % \changes{v1.2.5}{2024/01/26}{Support for locally defined \texttt{claimproof} environment}
1720 % If the |claimproof| environment exists (\textsf{lipics} document
1721 % class or user-defined), we also redefine it, in the same way.
1722 % \begin{macrocode}
1723 \AtBeginDocument{
1724 \ifdefined\claimproof
1725 \let\axp@oldclaimproof\claimproof
1726 \let\endaxp@oldclaimproof\endclaimproof
1727 \def\claimproof{\catcode`\^^M=\active\ltx@ifnextchar@nospace[{\catcode`\^^M=5\axp@@claimproof}{\catcode`\^^M=5\axp@claimproof}}
1728 \def\appendixclaimproof{\catcode`\^^M=\active\@ifnextchar[{\catcode`\^^M=5\@@appendixproof[axp@oldclaimproof]}{\catcode`\^^M=5\expandafter\@appendixproof[axp@oldclaimproof]}}
1729 \def\axp@claimproof
1730 {%
1731 \iftoggle{axp@seenreptheorem}{%
1732 \appendixclaimproof
1733 }{%
1734 \axp@oldclaimproof
1735 }%
1736 }
1737 \def\axp@@claimproof[#1]%
1738 {%
1739 \iftoggle{axp@seenreptheorem}{%
1740 \appendixclaimproof[#1]%
1741 }{%
1742 \axp@oldclaimproof[#1]%
1743 }%
1744 }
1745 \def\endclaimproof
1746 {%
1747 \iftoggle{axp@seenreptheorem}{%
1748 \endappendixclaimproof
1749 }{%
1750 \endaxp@oldclaimproof
1751 }%
1752 }
1753 \def\endappendixclaimproof
1754 {%
1755 \endaxp@VerbatimOut
1756 \immediate\write\axp@proofsfile{%
1757 \noexpand\end{axp@oldclaimproof}%
1758 }%
1759 \noproofinappendix
1760 }
1761 \fi
1762 }
1763 % \end{macrocode}
1764 % \end{environment}
1765
1766 % \begin{environment}{inlineproof}
1767 % \begin{environment}{nestedproof}
1768 % These two environments are synonyms for the original |proof|
1769 % environment.
1770 % \begin{macrocode}
1771 \let\inlineproof\axp@oldproof
1772 \let\endinlineproof\endaxp@oldproof
1773 \let\nestedproof\axp@oldproof
1774 \let\endnestedproof\endaxp@oldproof
1775 % \end{macrocode}
1776 % \end{environment}
1777 % \end{environment}
1778 % \subsubsection{Section Management}
1779 % \begin{macro}{axp@seccounter}
1780 % Sequentially incremented for every section, used to create labels.
1781 % \begin{macrocode}
1782 \newcounter{axp@seccounter}
1783 % \end{macrocode}
1784 % \end{macro}
1785 % \begin{macro}{\axp@sectitle}
1786 % Saves the title of the last encountered section.
1787 % \begin{macrocode}
1788 \def\axp@sectitle{}
1789 % \end{macrocode}
1790 % \end{macro}
1791 % \begin{macro}{\axp@section}
1792 % \changes{v1.2.2}{2021/06/23}{Detect a section within an included
1793 % file to avoid produced useless sections}
1794 % \changes{v1.3.0}{2026/04/09}{Skip blank lines before detecting
1795 % a section command}
1796 % \changes{v1.3.0}{2026/04/09}{Detect a section within an
1797 % \cs{include}'d file}
1798 % \begin{macro}{\axp@@sectionskippar}
1799 % \begin{macro}{\axp@@sectiontestinput}
1800 % \begin{macro}{\axp@@sectiontestinclude}
1801 % \begin{macro}{\axp@@sectionfinishinclude}
1802 % \begin{macro}{\axp@@sectiontestsection}
1803 % This command |\axp@section| behaves similarly to |\axp@oldsection|,
1804 % except that it first tests whether a |\section| follows, and if so,
1805 % does not produce anything. This is useful to avoid producing empty
1806 % sections in the appendix. Using the \textsf{catchfile} package, we
1807 % also check whether a |\section| is within an |\input| or |\include|
1808 % that immediately follows. We also skip any |\par| tokens (produced by
1809 % blank lines) before performing the check.
1810 % \begin{macrocode}
1811 \def\axp@section#1{%
1812 \@ifnextchar\par
1813 {\axp@@sectionskippar{#1}}%
1814 {\@ifnextchar\input
1815 {\axp@@sectiontestinput{#1}}%
1816 {\@ifnextchar\include
1817 {\axp@@sectiontestinclude{#1}}%
1818 {\axp@@sectiontestsection{#1}}}}%
1819 }
1820 \def\axp@@sectionskippar#1\par{\axp@section{#1}}
1821 \def\axp@@sectiontestinput#1\input#2{%
1822 \CatchFileDef{\axp@tmp}{#2}{}%
1823 \def\axp@tmptmp{\axp@@sectiontestsection{#1}}%
1824 \expandafter\axp@tmptmp\axp@tmp%
1825 }
1826 \def\axp@@sectiontestinclude#1\include#2{%
1827 \set@curr@file{#2}%
1828 \edef\axp@tmp{\@strip@tex@ext\@[email protected]}%
1829 \expandafter\CatchFileDef\expandafter\axp@tmp\expandafter{\axp@tmp}{}%
1830 \def\axp@tmptmp{\axp@@sectionfinishinclude{#1}{#2}}%
1831 \expandafter\axp@tmptmp\axp@tmp\@nil
1832 }
1833 \long\def\axp@@sectionfinishinclude#1#2#3#4\@nil{%
1834 \ifx#3\section
1835 \makeatother
1836 \else
1837 \axp@oldsection{#1}\makeatother
1838 \fi
1839 \include{#2}%
1840 }
1841 \def\axp@@sectiontestsection#1{\@ifnextchar\section{\makeatother}{\axp@oldsection{#1}\makeatother}}
1842 % \end{macrocode}
1843 % \end{macro}
1844 % \end{macro}
1845 % \end{macro}
1846 % \end{macro}
1847 % \end{macro}
1848 % \end{macro}
1849 % \begin{macro}{\axp@oldsection}
1850 % \begin{macro}{\section}
1851 % \changes{v1.1.0}{2018/07/25}{Rewrote definition of \cs{section}
1852 % to enable optional argument. See \#23. (K. D. Bauer)}
1853 % \changes{v1.1.0}{2018/07/25}{Fix handling of fragile macros within
1854 % section headings. See \#22.}
1855 % \begin{macro}{\@section}
1856 % \begin{macro}{\@@section}
1857 % We redefine the |\section| command to create a label based on
1858 % |axp@seccounter| and to store its title in |\axp@sectitle|.
1859 % In order to support starred and unstarred versions, as well
1860 % as the optional short-title argument, the intermediate macros
1861 % \cs{@section} and \cs{@@section} are needed.
1862 % \begin{macrocode}
1863 \let\axp@oldsection\section
1864 \def\section{\@ifstar\@section\@@section}
1865 \newcommand{\@section}[2][\relax]{\axp@@@section{*}{#1}{#2}}%
1866 \newcommand{\@@section}[2][\relax]{\axp@@@section{}{#1}{#2}}%
1867 \newcommand{\axp@@@section}[3]{%
1868 \global\def\axp@sectitle{#3}%
1869 \ifx\relax#2\relax
1870 \axp@oldsection#1{#3}%
1871 \else
1872 \axp@oldsection#1[{#2}]{#3}%
1873 \fi
1874 \addtocounter{axp@seccounter}{1}%
1875 \label{axp@s\roman{axp@seccounter}}%
1876 }
1877 % \end{macrocode}
1878 % \end{macro}
1879 % \end{macro}
1880 % \end{macro}
1881 % \end{macro}
1882 % \begin{macro}{\nosectionappendix}
1883 % We remove the current section title, to indicate no section should be
1884 % created in the appendix.
1885 % \begin{macrocode}
1886 \newcommand{\nosectionappendix}{
1887 \global\def\axp@sectitle{}%
1888 }
1889 % \end{macrocode}
1890 % \end{macro}
1891 % \begin{macro}{\axp@writesection}
1892 % If |\axp@sectitle| is not empty, we create
1893 % a new section in the appendix, referring to the main text section.
1894 %
1895 % Here, we wrap |\ref{axp@si}| into |\axp@protectref@i|, in order
1896 % to protect the label name from wrongly being converted to uppercase,
1897 % e.g., in \textsf{fancyhdr} with |\pagestyle{fancy}|.
1898 %
1899 % This macro is defined both in the |.aux| file (in order to ensure availability
1900 % when typesetting the |\tableofcontents|), and immediately before typesetting
1901 % the appendix section (to ensure availability in the |\section| command).
1902 %
1903 % \changes{v1.0.6}{2018/05/10}{Fix extraneous space after section number
1904 % in appendix titles}
1905 % \changes{v1.1.0}{2018/07/09}{Make \cs{axp@tmp} wrapper more robust.
1906 % Resolves issues from use of section title in \textsf{fancyhdr},
1907 % and in \cs{tableofcontents} (K. D. Bauer).}
1908 % \begin{macrocode}
1909 \newcommand\axp@writesection{%
1910 \ifx\axp@sectitle\@empty
1911 \else
1912 \edef\axp@tmp{%
1913 \noexpand\global\noexpand\def
1914 \expandonce{\csname axp@protectref@\roman{axp@seccounter}\endcsname}{%
1915 \noexpand\ref{axp@s\roman{axp@seccounter}}%
1916 }%
1917 }%
1918 \immediate\write\@auxout{\expandonce\axp@tmp}
1919 \immediate\write\axp@proofsfile{%
1920 \expandonce\axp@tmp^^J%
1921 \noexpand\axp@section{%
1922 \noexpand\appendixsectionformat{%
1923 \protect
1924 \expandonce{\csname axp@protectref@\roman{axp@seccounter}\endcsname}%
1925 }{\expandonce\axp@sectitle}%
1926 }%
1927 }%
1928 \nosectionappendix
1929 \fi
1930 }
1931 % \end{macrocode}
1932 % \end{macro}
1933 % Finally, in a somewhat ad hoc manner, we disable the whole section management
1934 % for \cs{tableofcontents}, which may be typeset using a section heading,
1935 % but for which automatic section management does not make sense.
1936 %
1937 % \begin{macro}{\axp@oldtableofcontents}
1938 % \begin{macro}{\tableofcontents}
1939 % \changes{v1.1.0}{2018/07/09}{Disable section management for table
1940 % of contents}
1941 % \begin{macrocode}
1942 \let\axp@oldtableofcontents\tableofcontents
1943 \def\tableofcontents{{\let\section\axp@oldsection\axp@oldtableofcontents}}
1944 % \end{macrocode}
1945 % \end{macro}
1946 % \end{macro}
1947 % \subsubsection{Append Compilation Mode}
1948 % \begin{macrocode}
1949 \ifthenelse{\equal{\axp@appendix}{append}}{
1950 % \end{macrocode}
1951 % \begin{macro}{\axp@oldbibliography}
1952 % \begin{macro}{\bibliography}
1953 % In |bibengine=bibtex| mode, when the |bibliography| option is set to
1954 % |separate|, we need to set the appendix bibliography source to be
1955 % the same as that of the main text, thanks to \textsf{bibunits}'s
1956 % |\defaultbibliography| macro. In |bibengine=biblatex| mode, no such
1957 % rebinding is needed: \textsf{biblatex} resources declared with
1958 % |\addbibresource| are visible to all |refsection|s globally.
1959 % \changes{v1.4.0}{2026/05/14}{Only rebind for bibunits engine.
1960 % See \#29.}
1961 % \begin{macrocode}
1962 \ifthenelse{\equal{\axp@bibliography}{separate}
1963 \AND\equal{\axp@bibengine}{bibtex}}{
1964 \let\axp@oldbibliography\bibliography
1965 \renewcommand\bibliography[1]{%
1966 \defaultbibliography{#1}%
1967 \axp@oldbibliography{#1}%
1968 }
1969 }{}
1970 % \end{macrocode}
1971 % \end{macro}
1972 % \end{macro}
1973 % After the end of the main text, we add the appendix (after the command
1974 % |\appendixprelim| is issued)
1975 % within a |bibunit| environment so as to typeset
1976 % a separate bibliography for the appendix (unless the |bibliography|
1977 % option is set to |common|). This is done using |\pretocmd| on
1978 % |\@enddocumenthook| instead of |\AtEndDocument| because we want the
1979 % code to be run before any code in the |\@enddocumenthook| that has
1980 % been set in the document class, as in the \textsf{amsart} document
1981 % class.
1982 % \changes{v1.2.2}{2021/03/23}{Compatibility with AMS document classes: do not
1983 % use \texttt{\textbackslash AtEndDocument}}
1984 % There is an extra test to
1985 % ensure an empty bibliography environment is not produced.
1986 % The name of the bibliography is changed to |\appendixrefname|; in most
1987 % document classes, it is called |\refname| but it is occasionally
1988 % (|scrartcl|, |scrreprt|) called |\bibname|. An ad-hoc test is added
1989 % to fix a conflict with the \textsf{natbib} package which redefines
1990 % |bibcite| at the end of the document.
1991 % \changes{v1.0.6}{2018/05/10}{Deal with document classes where the
1992 % bibliography is called \texttt{\textbackslash bibname}}
1993 % \changes{v1.2.1}{2020/02/27}{Ad hoc fix for \textsf{natbib}
1994 % package conflict}
1995 % \changes{v1.2.3}{2021/08/03}{More robust redefinition of
1996 % \texttt{thebibliography} environment, for compatibility with
1997 % \textsf{tocbibind}}
1998 % \begin{macrocode}
1999 \pretocmd{\@enddocumenthook}{%
2000 \ifdefined\NAT@testdef
2001 \renewcommand\bibcite[2]{%
2002 \global\@namedef{b@#1\@extra@binfo}{#2}%
2003 }
2004 \fi
2005 \appendixprelim
2006 \appendix
2007 \ifthenelse{\equal{\axp@bibliography}{separate}}{
2008 \ifthenelse{\equal{\axp@bibengine}{bibtex}}{
2009 \begin{bibunit}[\appendixbibliographystyle]
2010 }{
2011 \begin{refsection}
2012 }
2013 }{}
2014 \immediate\closeout\axp@proofsfile
2015 \input{\jobname.axp}
2016 \ifthenelse{\equal{\axp@bibliography}{separate}}{
2017 \ifthenelse{\equal{\axp@bibengine}{bibtex}}{
2018 \ifdefined\refname
2019 \renewcommand{\refname}{\appendixrefname}
2020 \else\ifdefined\bibname
2021 \renewcommand{\bibname}{\appendixrefname}
2022 \fi\fi
2023 \let\axp@oldthebibliography\thebibliography
2024 \let\endaxp@oldthebibliography\endthebibliography
2025 \renewenvironment{thebibliography}[1]{%
2026 \def\axp@tmp{#1}%
2027 \ifx\axp@tmp\empty
2028 \gdef\axp@noappendixbibliography1\relax
2029 \else
2030 \begin{axp@oldthebibliography}{#1}%
2031 \fi
2032 }{%
2033 \ifdefined\axp@noappendixbibliography\relax\else\end{axp@oldthebibliography}%
2034 \fi}
2035 \appendixbibliographyprelim
2036 \putbib
2037 \end{bibunit}
2038 }{
2039 \appendixbibliographyprelim
2040 \printbibliography[title=\appendixrefname]
2041 \end{refsection}
2042 }
2043 \ifdefined\NAT@testdef
2044 \let\bibcite\NAT@testdef
2045 \fi
2046 }{}
2047 }{}{}
2048 % \end{macrocode}
2049 % \begin{macrocode}
2050 }{}
2051 % \end{macrocode}
2052 % \subsubsection{Chapter End Compilation Mode}
2053 % \changes{v1.3.0}{2026/04/14}{Added \texttt{chapterend} appendix mode}
2054 % \changes{v1.4.0}{2026/04/29}{Flush \texttt{chapterend} appendices at
2055 % \cs{part}, \cs{frontmatter}, \cs{mainmatter}, and \cs{backmatter}
2056 % boundaries so the last chapter of a part/matter is not emitted under
2057 % the next one}
2058 % \changes{v1.4.0}{2026/04/29}{Public \cs{flushchapterappendix} macro
2059 % for manually emitting the current chapter's accumulated appendix in
2060 % \texttt{chapterend} mode}
2061 % In |chapterend| mode, appendix material for each chapter is gathered
2062 % in a per-chapter auxiliary file and emitted immediately after that
2063 % chapter's content (and bibliography). This requires the
2064 % \textsf{appendix} package for its |subappendices| environment.
2065 % \begin{macrocode}
2066 \ifthenelse{\equal{\axp@appendix}{chapterend}}{
2067 % \end{macrocode}
2068 % \begin{macrocode}
2069 \RequirePackage{appendix}
2070 % \end{macrocode}
2071 % \begin{macro}{\chapterappendixprelim}
2072 % \begin{macro}{\axp@beginchapterappendix}
2073 % \begin{macro}{\axp@endchapterappendix}
2074 % User-customizable hooks surrounding each chapter's appendix block.
2075 % By default they open and close a |subappendices| environment.
2076 % \begin{macrocode}
2077 \newcommand{\chapterappendixprelim}{\clearpage}
2078 \newcommand{\axp@beginchapterappendix}{%
2079 \chapterappendixprelim
2080 \begin{subappendices}%
2081 }
2082 \newcommand{\axp@endchapterappendix}{%
2083 \end{subappendices}%
2084 }
2085 % \end{macrocode}
2086 % \end{macro}
2087 % \end{macro}
2088 % \end{macro}
2089 % \begin{macro}{axp@chaptercounter}
2090 % \begin{macro}{axp@chapterhasappendix}
2091 % \begin{macro}{\axp@currentaxpfile}
2092 % Counter for unique per-chapter file names, a boolean tracking whether
2093 % the current chapter has any appendix content, and the current file name.
2094 % \begin{macrocode}
2095 \newcounter{axp@chaptercounter}
2096 \newbool{axp@chapterhasappendix}
2097 \def\axp@currentaxpfile{}
2098 % \end{macrocode}
2099 % \end{macro}
2100 % \end{macro}
2101 % \end{macro}
2102 % \begin{macro}{\axp@markchapterhasappendix}
2103 % Override the no-op to set the boolean when content is written.
2104 % \begin{macrocode}
2105 \renewcommand{\axp@markchapterhasappendix}{%
2106 \global\booltrue{axp@chapterhasappendix}%
2107 }
2108 % \end{macrocode}
2109 % \end{macro}
2110 % \begin{macro}{\axp@openchapterfile}
2111 % Open a fresh auxiliary file for the current chapter.
2112 % We write |\begingroup| first so that all the preamble |\let|
2113 % assignments (and any catcode changes from |\makeatletter|) are
2114 % scoped to this chapter's appendix and do not leak into the rest of
2115 % the document when the file is |\input|'d. We also reset the
2116 % section-title tracker and the repeated-theorem toggle so that state
2117 % from the previous chapter cannot bleed into the new file.
2118 % \begin{macrocode}
2119 \newcommand{\axp@openchapterfile}{%
2120 \edef\axp@currentaxpfile{\jobname-\arabic{axp@chaptercounter}.axp}%
2121 \immediate\openout\axp@proofsfile=\axp@currentaxpfile
2122 \immediate\write\axp@proofsfile{\noexpand\begingroup}%
2123 \axp@writeproofsfilepreamble
2124 \global\boolfalse{axp@chapterhasappendix}%
2125 \global\def\axp@sectitle{}%
2126 \global\togglefalse{axp@seenreptheorem}%
2127 }
2128 % \end{macrocode}
2129 % \end{macro}
2130 % \begin{macro}{\axp@flushchapterappendix}
2131 % Close the current chapter's auxiliary file (appending |\endgroup|
2132 % to close the group opened in |\axp@openchapterfile|) and, if it
2133 % contains any content, emit it inside a |subappendices| block.
2134 % \begin{macrocode}
2135 \newcommand{\axp@flushchapterappendix}{%
2136 \immediate\write\axp@proofsfile{\noexpand\endgroup}%
2137 \immediate\closeout\axp@proofsfile
2138 \ifbool{axp@chapterhasappendix}{%
2139 \axp@beginchapterappendix
2140 \input{\axp@currentaxpfile}%
2141 \axp@endchapterappendix
2142 }{}%
2143 }
2144 % \end{macrocode}
2145 % \end{macro}
2146 % \begin{macro}{\axp@chapterboundary}
2147 % \begin{macro}{\flushchapterappendix}
2148 % |\axp@chapterboundary| flushes the previous chapter's auxiliary file,
2149 % increments the counter, and opens the next one. It is used as a hook
2150 % for |\chapter|, |\part|, and the |book|-class matter-switching
2151 % commands |\frontmatter|, |\mainmatter|, |\backmatter|, so that
2152 % per-chapter appendices are emitted before any of these structural
2153 % transitions (otherwise the appendix of the last chapter of a
2154 % part/matter would end up under the next part/matter).
2155 % |\flushchapterappendix| is a public alias for the same operation,
2156 % which can be invoked manually wherever an appendix flush boundary is
2157 % needed (e.g., before a bibliography that does not produce its own
2158 % chapter heading).
2159 % \begin{macrocode}
2160 \newcommand{\axp@chapterboundary}{%
2161 \axp@flushchapterappendix
2162 \stepcounter{axp@chaptercounter}%
2163 \axp@openchapterfile
2164 }
2165 \let\flushchapterappendix\axp@chapterboundary
2166 % \end{macrocode}
2167 % \end{macro}
2168 % \end{macro}
2169 % \begin{macro}{\axp@hookboundary}
2170 % Helper to install |\axp@chapterboundary| as a |\pretocmd| hook on a
2171 % structural command (|\chapter|, |\part|, |\frontmatter|, etc.),
2172 % issuing a package warning if the hook fails.
2173 % \begin{macrocode}
2174 \newcommand{\axp@hookboundary}[1]{%
2175 \pretocmd{#1}{\axp@chapterboundary}{}{%
2176 \PackageWarning{apxproof}{%
2177 Could not hook into \string#1;^^J%
2178 chapter appendices may not be emitted correctly}}%
2179 }
2180 % \end{macrocode}
2181 % \end{macro}
2182 % At the start of each |\chapter|, |\part|, or matter-switching
2183 % command, run the boundary hook. At |\end{document}|, flush the
2184 % last chapter's file.
2185 % \begin{macrocode}
2186 \AtBeginDocument{%
2187 \ifdef{\chapter}{%
2188 \axp@hookboundary{\chapter}%
2189 }{%
2190 \PackageWarning{apxproof}{%
2191 appendix=chapterend used but \string\chapter\space
2192 is not defined}%
2193 }%
2194 \ifdef{\part}{\axp@hookboundary{\part}}{}%
2195 \ifdef{\frontmatter}{\axp@hookboundary{\frontmatter}}{}%
2196 \ifdef{\mainmatter}{\axp@hookboundary{\mainmatter}}{}%
2197 \ifdef{\backmatter}{\axp@hookboundary{\backmatter}}{}%
2198 }
2199 \pretocmd{\@enddocumenthook}{%
2200 \axp@flushchapterappendix
2201 }{}{}
2202 % \end{macrocode}
2203 % \begin{macrocode}
2204 }{}
2205 % \end{macrocode}
2206 % \subsubsection{Class-Specific Behavior}
2207 % We conclude with some class-specific behavior.
2208 % \paragraph{ACM Document Classes (old versions, till 2017)}
2209 % \changes{v1.0.4}{2017/03/08}{More faithful theorem style for ACM templates}
2210 % \changes{v1.0.4}{2017/03/08}{More robust coherent styling of proof sketches}
2211 % \begin{macrocode}
2212 \ifdefined\@acmtitlebox
2213 % \end{macrocode}
2214 % We first redefine the |proofsketch| environment, which is used
2215 % differently in the base class.
2216 % \begin{macrocode}
2217 \renewenvironment{proofsketch}{\begin{axp@oldproof}[sketch]}{\end{axp@oldproof}}
2218 % \end{macrocode}
2219 % We adjust the styling of theorems for the needs of \textsf{apxproof}.
2220 % \begin{macrocode}
2221 \newtheoremstyle{mystyle}
2222 {6pt}
2223 {6pt}
2224 {\itshape}
2225 {10pt}
2226 {\scshape}
2227 {.}
2228 {.5em}
2229 {}
2230 \theoremstyle{mystyle}
2231 % \end{macrocode}
2232 % \begin{macro}{\thebibliography}
2233 % \begin{macro}{\refname}
2234 % \begin{macro}{\appendixrefname}
2235 % The section title of the bibliography is in uppercase in these document
2236 % classes. In addition, the |\thebibliography| macro hard-codes twice
2237 % the section title, so we un-hardcode it so that it can be modified
2238 % in the appendix.
2239 % \begin{macrocode}
2240 \patchcmd{\thebibliography}{References}{\protect\refname}{}{}
2241 \patchcmd{\thebibliography}{References}{\protect\refname}{}{}
2242 \newcommand{\refname}{REFERENCES}
2243 \renewcommand{\appendixrefname}{REFERENCES FOR THE APPENDIX}
2244 % \end{macrocode}
2245 % \end{macro}
2246 % \end{macro}
2247 % \end{macro}
2248 %
2249 % \begin{macrocode}
2250 \fi
2251 % \end{macrocode}
2252 % \changes{v1.0.6}{2018/05/10}{Support of new ACM document class
2253 % (\texttt{acmart.cls})}
2254 % \paragraph{\textsf{lipcs}}
2255 % \begin{macrocode}
2256 \ifdefined\lipics@opterrshort
2257 % \end{macrocode}
2258 % \begin{macro}{\appendixbibliographyprelim}
2259 % \changes{v1.0.3}{2017/02/06}{Support for lipics-v2016}
2260 % The default bibliography in the \textsf{lipics} document class
2261 % formatting is not compatible with the
2262 % \textsf{alpha} bibliography style. We fix this here.
2263 % \begin{macrocode}
2264 \renewcommand{\appendixbibliographyprelim}{%
2265 \global\let\@oldbiblabel\@biblabel
2266 \def\@biblabel{\hspace*{-2em}\small\@oldbiblabel}%
2267 }
2268 % \end{macrocode}
2269 % \end{macro}
2270 % \begin{macrocode}
2271 \fi
2272 }
2273 % \end{macrocode}
2274 % \Finale
2275 % \bibliographystyle{plain}
2276 % \bibliography{apxproof}