texlive[48377] Master/texmf-dist: apxproof (8aug18)

commits+karl at tug.org commits+karl at tug.org
Wed Aug 8 23:06:12 CEST 2018


Revision: 48377
          http://tug.org/svn/texlive?view=revision&revision=48377
Author:   karl
Date:     2018-08-08 23:06:12 +0200 (Wed, 08 Aug 2018)
Log Message:
-----------
apxproof (8aug18)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/apxproof/apxproof.pdf
    trunk/Master/texmf-dist/source/latex/apxproof/apxproof.dtx
    trunk/Master/texmf-dist/tex/latex/apxproof/apxproof.sty

Modified: trunk/Master/texmf-dist/doc/latex/apxproof/apxproof.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/apxproof/apxproof.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/apxproof/apxproof.dtx	2018-08-08 21:05:58 UTC (rev 48376)
+++ trunk/Master/texmf-dist/source/latex/apxproof/apxproof.dtx	2018-08-08 21:06:12 UTC (rev 48377)
@@ -24,7 +24,7 @@
 % \iffalse
 %<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
 %<package>\ProvidesPackage{apxproof}
-%<package>  [2018/05/10 v1.0.6 Automatic proofs in appendix]
+%<package>  [2018/08/08 v1.1.0 Automatic proofs in appendix]
 %
 %<*driver>
 \documentclass{ltxdoc}
@@ -32,6 +32,7 @@
 \usepackage{hypdoc}
 \usepackage{textcomp}
 \usepackage[TS1,T1]{fontenc}
+\usepackage{lmodern}
 \usepackage{microtype}
 \newtheorem{example}{Example}
 \newtheoremrep{foobar}{Foobar}
@@ -44,7 +45,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{562}
+% \CheckSum{716}
 %
 % \CharacterTable
 %  {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
@@ -249,6 +250,7 @@
 % \begin{proof}
 % This is the proof of the regular foobar.
 % \end{proof}
+% Now, if we use a repeated theorem:
 % \begin{quote}
 % \begin{verbatim}
 % \begin{foobarrep}
@@ -268,9 +270,9 @@
 This is the proof of the repeated foobar.
 %</driver>
 % \end{proof}
-% Note that, since |hyperref| is loaded, there is a hyperlink
-% created from the statement of the theorem in the appendix to that in
-% the main text.
+% Note that, since |hyperref| is loaded, there are hyperlinks
+% created between the statements of the theorems in the main text and in
+% the appendix.
 % \end{example}
 %
 % When the proof is deferred to the appendix, it is common practice to
@@ -285,7 +287,7 @@
 % The proof sketch is typeset similarly to a proof, but is always in the
 % main text. Similarly, an |inlineproof| \DescribeEnv{inlineproof}
 % environment is provided so as to
-% be able to have both a proof in the appendix (using the regualr |proof|
+% be able to have both a proof in the appendix (using the regular |proof|
 % environment, or alternatively the |appendixproof| environment) and a
 % different proof in the main text (using the |inlineproof| environment).
 % \begin{example} Here are simple examples of proof sketches and inline
@@ -381,6 +383,17 @@
 % in single-column mode) but redefining this option allows changing this
 % behavior.
 % \end{description}
+% \DescribeOption{repeqn}
+% Another customization capability concerns \emph{numbered equations} that are present
+% within repeated theorems. An optional |repeqn| option can be specified
+% when loading the package, which controls whether
+% equation numbers should be as in the same text (by setting this option
+% to |same|, the default) or independently
+% numbered (by setting this option to |independent|). In the latter case,
+% whenever a referenceable counter is set with |\label{|\meta{counter}|}|,
+% |\ref{|\meta{counter}|}| references the counter in the main text, while
+% |\ref{|\meta{counter}|-apx}| references the counter in the appendix
+% (except in |inline| mode, where both have the same effect).
 %
 % \subsection{Advanced Features}
 % We now describe a few advanced macros and environments, whose usage is limited to
@@ -412,9 +425,9 @@
 % \begin{itemize}
 % \item \LaTeX{} standard document classes (e.g., |article.cls|)
 % \item \href{https://www.ctan.org/pkg/koma-script}{KOMA-Script}
-% (e.g., |scrartcl.cls|)
+% (e.g., |scrartcl.cls|, |scrbook.cls|)
 % \item \href{https://www.acm.org/publications/proceedings-template}{ACM
-% SIG Proceedings} (e.g., |sig-alternate.cls|)
+% SIG Proceedings} (e.g., |sig-alternate.cls|, |acmart.cls|)
 % \item \href{https://www.springer.com/computer/lncs/lncs+authors}{
 % Springer's Lecture Notes in Computer Science} (e.g.,
 % |llncs.cls|)
@@ -421,7 +434,7 @@
 % \item
 % \href{https://www.dagstuhl.de/en/publications/lipics}{Schlo\ss{}
 % Dagstuhl's Leibniz International Proceedings in Informatics} (e.g.,
-% |lipics.cls|)
+% |lipics.cls|, |lipcs-v2016.cls|)
 % \end{itemize}
 % Other classes may work out of the box. Adding support for specific
 % classes is possible and can be requested from the
@@ -438,12 +451,16 @@
 % \item \textsf{apxproof} is incompatible with a separate use of the
 % \textsf{fancyvrb} package. This is because \textsf{apxproof} redefines
 % some internal mechanisms of \textsf{fancyvrb}.
+% \item \textsf{apxproof} poorly interacts with Sync\TeX: identifying
+% which source line has produced which box does not work for appendix
+% content managed by \textsf{apxproof} or repeated theorems. No obvious
+% fix is known, though this issue will be investigated in the long term.
 % \end{itemize}
 %
 % Issues not listed here should be reported to the author.
 %
 % \section{License}
-% Copyright \textcopyright{} 2016--2017 by Pierre Senellart.
+% Copyright \textcopyright{} 2016--2018 by Pierre Senellart.
 % 
 % This work may be distributed and/or modified under the conditions of the
 % \LaTeX{} Project Public License, either version 1.3 of this license or (at
@@ -462,7 +479,9 @@
 % preferably be submitted through the \emph{Issues} feature of GitHub.
 %
 % \section{Acknowledgments}
-% Thanks to Antoine Amarilli for feedback and proofreading. 
+% Thanks to Antoine Amarilli for feedback and proofreading. Thanks to K.~D.
+% Bauer for the implementation of the forward-linking mechanism, and
+% for various bugfixes.
 %
 % \StopEventually{
 %   \PrintChanges
@@ -549,6 +568,8 @@
 %     values: |strip|, |inline|);
 %   \item |bibliography|, with a default value of |separate| (other
 %     possible value: |common|);
+%   \item |repeqn|, with a default value of |same| (other possible value:
+%   |independent|).
 % \end{itemize}
 % \begin{macro}{\axp at appendix}
 %    \begin{macrocode}
@@ -561,11 +582,16 @@
 \DeclareStringOption[separate]{bibliography}
 %    \end{macrocode}
 % \end{macro}
+% \begin{macro}{\axp at repeqn}
+% \changes{v1.1.0}{2018/07/20}{\texttt{repeqn} option}
 %    \begin{macrocode}
+\DeclareStringOption[same]{repeqn}
+%    \end{macrocode}
+% \end{macro}
+%    \begin{macrocode}
 \ProcessLocalKeyvalOptions*
 %    \end{macrocode}
-% We check that the value of the |appendix| and
-% |bibliography| options are valid, and add a
+% We check that the value of the options are valid, and add a
 % message to the compilation log.
 %    \begin{macrocode}
 \ifthenelse{\equal{\axp at appendix}{append}}{
@@ -575,7 +601,7 @@
 }{\ifthenelse{\equal{\axp at appendix}{inline}}{
   \message{apxproof: Appendix material inlined within the document}
 }{
-  \errmessage{Error: unsupported option appendix=\axp at appendix for
+  \errmessage{Error: unsupported option appendix=\axp at appendix\ for
   package apxproof}
 }}}
 \ifthenelse{\equal{\axp at bibliography}{separate}}{
@@ -583,9 +609,17 @@
 }{\ifthenelse{\equal{\axp at bibliography}{common}}{
   \message{apxproof: Common bibliography for appendix and main text}
 }{
-  \errmessage{Error: unsupported option bibliography=\axp at bibliography for
+  \errmessage{Error: unsupported option bibliography=\axp at bibliography\ for
   package apxproof}
 }}
+\ifthenelse{\equal{\axp at repeqn}{same}}{
+  \message{apxproof: Repeated equations keep the same numbering}
+}{\ifthenelse{\equal{\axp at repeqn}{independent}}{
+  \message{apxproof: Repeated equations are independently numbered}
+}{
+  \errmessage{Error: unsupported option repeqn=\axp at repeqn\ for
+  package apxproof}
+}}
 %    \end{macrocode}
 % \subsection{Macros Common to All Compilation Modes}
 % \begin{macro}{\axp at newtheorem}
@@ -658,6 +692,8 @@
 % \begin{macro}{\appendixprelim}
 % \changes{v1.0.4}{2017/03/03}{Configurable appendix style}
 % \begin{macro}{\appendixsectionformat}
+% \changes{v1.1.0}{2018/07/17}{Fix missing space in default
+% \cs{appendixsectionformat}}
 % We provide sensible defaults for these four user-customizable macros.
 % Even though they are only useful in append mode, we define them for
 % all modes so that a |\renewcommand| works in all cases.
@@ -666,7 +702,7 @@
 \newcommand{\appendixbibliographystyle}{alpha}
 \newcommand{\appendixbibliographyprelim}{}
 \newcommand{\appendixprelim}{\clearpage\onecolumn}
-\newcommand{\appendixsectionformat}[2]{Proofs for Section~#1 (#2)}
+\newcommand{\appendixsectionformat}[2]{Proofs for Section~#1\ (#2)}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -680,6 +716,37 @@
   \let\endaxp at oldproof\endproof
 %    \end{macrocode}  
 % \end{environment}
+% We define a utility macro that will be used to properly set the
+% |\label| command (and its \textsf{amsmath} counterpart,
+% |\label at in@display|) for equations within repeated theorems, depending on the
+% compilation mode.
+% \begin{macro}{\axp at redefinelabels}
+% \changes{v1.1.0}{2018/07/04}{Fix \cs{label} not being disabled
+% in \textsf{amsmath} environments, where \cs{label at in@display} is
+% used instead (K. D. Bauer)}
+%    \begin{macrocode}  
+  \newcommand{\axp at redefinelabels}{%
+    \providecommand\label at in@display{}
+    \ifthenelse{\equal{\axp at appendix}{inline}}{
+      \let\axp at oldlabel\label
+      \let\axp at oldlabel@in at display\label at in@display
+      \renewcommand\label[1]{%
+        \axp at oldlabel{##1}%
+        \axp at oldlabel{##1-apx}%
+      }%
+      \renewcommand\label at in@display[1]{%
+        \axp at oldlabel@in at display{##1}%
+        \axp at oldlabel{##1-apx}%
+      }%
+    }{%
+      \let\axp at oldlabel\label
+      \let\axp at oldlabel@in at display\label at in@display
+      \renewcommand\label[1]{\axp at oldlabel{##1-apx}}%
+      \renewcommand\label at in@display[1]{\axp at oldlabel@in at display{##1-apx}}%
+    }%
+  }
+%    \end{macrocode}  
+% \end{macro}  
 % \subsubsection{Class-Specific Behavior}    
 % Finally, some class-specific behavior common to all compilation modes  
 % \paragraph{\textsf{llncs} and other Springer document classes}
@@ -734,7 +801,9 @@
 % In inline mode, |\axp at newtheoremrep| undefines the existing
 % theorem environment if it has already been defined (e.g., by the
 % document class), invokes |\newtheorem| and creates a repeated theorem
-% environment that behaves exactly as the regular theorem environment.
+% environment that behaves exactly as the regular theorem environment,
+% while calling |\axp at redefinelabels| to make sure that |-axp| variants
+% of equation counters are defined.
 %    \begin{macrocode}
   \def\axp at newtheoremrep#1[#2]#3[#4]{%
     \expandafter\let\csname #1\endcsname\undefined
@@ -741,7 +810,7 @@
     \expandafter\let\csname c@#1\endcsname\undefined
     \axp at newtheorem{#1}{#2}{#3}{#4}%
     \NewEnviron{#1rep}[1][]{%
-      \begin{#1}[##1]\BODY\end{#1}%
+      \begin{#1}[##1]\axp at redefinelabels\BODY\end{#1}%
     }
   }
 %    \end{macrocode}
@@ -789,9 +858,14 @@
 % \begin{macro}{\axp at proofsfile}  
 % We open a new auxiliary file, with extension |.axp|, where the appendix
 % material will be dumped.  
+% \changes{v1.1.0}{2018/07/11}{Initialization deferred to \cs{AtBeginDocument}
+% for compatibility with \cs{dump}ed precompiled preambles (K. D.
+% Bauer)}
 %    \begin{macrocode}  
-  \newwrite\axp at proofsfile
-  \immediate\openout\axp at proofsfile=\jobname.axp
+  \AtBeginDocument{
+    \newwrite\axp at proofsfile
+    \immediate\openout\axp at proofsfile=\jobname.axp
+  }
 %    \end{macrocode}  
 % \end{macro}  
 % \begin{environment}{proof}
@@ -800,11 +874,13 @@
 % it will be used in several places for internal names) and reestablish the original definition of
 % the |proof| environment and the |\section| macro.
 %    \begin{macrocode}  
-  \immediate\write\axp at proofsfile{%
-    \noexpand\makeatletter
-    \noexpand\let\noexpand\proof\noexpand\axp at oldproof
-    \noexpand\let\noexpand\endproof\noexpand\endaxp at oldproof
-    \noexpand\let\noexpand\section\noexpand\axp at oldsection
+  \AtBeginDocument{
+    \immediate\write\axp at proofsfile{%
+      \noexpand\makeatletter
+      \noexpand\let\noexpand\proof\noexpand\axp at oldproof
+      \noexpand\let\noexpand\endproof\noexpand\endaxp at oldproof
+      \noexpand\let\noexpand\section\noexpand\axp at oldsection
+    }
   }
 %    \end{macrocode}  
 % \end{macro}  
@@ -853,6 +929,16 @@
   \newcounter{axp at rpcounter}
 %    \end{macrocode}  
 % \end{macro}  
+% \begin{macro}{axp at equation}
+% \begin{macro}{axp at equationx}
+% Used to save the value of the |equation| counter, when |repeqn| is set
+% to |same|.
+%    \begin{macrocode}  
+  \newcounter{axp at equation}
+  \newcounter{axp at equationx}
+%    \end{macrocode}  
+% \end{macro}
+% \end{macro}
 % \begin{macro}{axp at newtheoremrep}
 % When called with first argument |foobar|, we first undefine the existing
 % |foobar| environment (and its counter) if it has already been defined (e.g., by the
@@ -867,6 +953,7 @@
     \axp at newtheorem{#1}{#2}{#3}{#4}%
     \expandafter\pretocmd\csname #1\endcsname{\noproofinappendix}{}{}%
     \axp at newtheorem*{axp@#1rp}{#3}%
+    \axp at forward@setup{#1}{#2}{#3}{#4}%
 %    \end{macrocode}  
 % We then define a |foobarrep| environment that increments the
 % |axp at rpcounter| and typeset the regular |foobar| theorem with a label
@@ -875,13 +962,19 @@
 % \changes{v1.0.6}{2018/05/10}{Better handling of note-free theorems in
 % document classes that treat theorems differently when they have an
 % empty note}
-%    \begin{macrocode}  
+% We save the equation counter
+% before typesetting the theorem environment, to reset it to the same
+% value in the repeated environment when |repeqn| is set to |same|.
+%    \begin{macrocode}
     \NewEnviron{#1rep}[1][]{%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \setcounter{axp at equation}{\value{equation}}%
+      }{}%
       \addtocounter{axp at rpcounter}{1}%
       \ifx\relax##1\relax
-        \begin{#1}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
+        \axp at with@forward{#1}{\begin{#1}}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
       \else
-        \begin{#1}[##1]\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
+        \axp at with@forward{#1}{\begin{#1}[##1]}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
       \fi    
 %    \end{macrocode}  
 % We set the |axp at seenreptheorem| toggle to indicate that we are looking
@@ -896,7 +989,7 @@
 % Possibly after starting a new appendix section if needed, we typeset a
 % repeated version of the theorem using the |axp at foobarrp| environment
 % and a reference to the previously defined label.
-% We ignore any use of |\label| in this environment to avoid multiply
+% We use |\axp at redefinelabels| in this environment to avoid multiply
 % defined labels.
 % \changes{v1.0.2}{2016/12/13}{Fix missing space between repeated theorem
 % counter and theorem note}
@@ -904,19 +997,140 @@
 % in optional argument of macro environment}
 %    \begin{macrocode}  
       \axp at writesection%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \immediate\write\axp at proofsfile{%
+          \noexpand\setcounter{axp at equationx}{\value{equation}}%
+          \noexpand\setcounter{equation}{\theaxp at equation}%
+        }%
+      }{}%
       \immediate\write\axp at proofsfile{%
         \noexpand\begin{axp@#1rp}
           [\noexpand\ref{axp at r\roman{axp at rpcounter}}%
            \@ifnotempty{##1}{ \unexpanded{##1}}]%
-          \noexpand\let\noexpand\label\noexpand\@gobble%
+          \noexpand\axp at forward@target{axp at fw@r\roman{axp at rpcounter}}{}%
+          \noexpand\axp at redefinelabels
           \expandafter\noexpand\csname rplet\roman{axp at rpcounter}%
                                \endcsname
         \noexpand\end{axp@#1rp}
-      }
-    }
+      }%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \immediate\write\axp at proofsfile{%
+          \noexpand\setcounter{equation}{\value{axp at equationx}}%
+        }%
+      }{}%
+    }%
   }
-%    \end{macrocode}  
+%    \end{macrocode}
 % \end{macro}  
+% 
+%    \subsubsection{Forward-Linking Mechanism}
+% \changes{v1.1.0}{2018/07/02}{Added forward-link mechanism (K. D. Bauer)}
+% 
+% When hyperref is loaded, |foobarrep| environments
+% in the main text have their number link to their
+% repetition in the appendix.
+% 
+%   
+
+% 
+% \begin{macro}{\axp at with@forward}
+% In order to make the number of the |foobarrep| theorem a link
+% to its repeated version, we temporarily redefine the
+% |\thefoobar| command, or, if we inherited the counter
+% from a |bazbar| environment, the |\thebazbar| command.
+% This seems to be the only robust way, to make the number
+% a |\hyperlink|, without adding extensive dependence
+% on internals of |amsthm|, the builtin |\newtheorem|
+% and possibly document-class specific definitions.
+% 
+% In order to allow users to redefine |\thefoobar| without
+% breaking this feature, we redefine |\thefoobar| only
+% for the duration of the |\begin{foobar}| form,
+% resetting it to the old value as soon as possible.
+%
+% Redefining |\thefoobar| has the side effect of changing |\newlabel| entries
+% in the |.aux| file, so we need to to be able to disable
+% addition of the hyperlink, which is why we use an
+% intermediate |\axp at forward@link|\marg{target}\marg{text} macro,
+% We also redefine |\theHfoobar| which is used by |hyperref| but not
+% defined if |hyperref| was loaded after |\newtheoremrep| was used.
+% and |\protect| it to output it verbatim into the |.aux| file.
+% 
+% These hyperlinks are of course disabled in the |strip| compilation
+% mode.
+%    \begin{macrocode}
+   \newcommand{\axp at with@forward}[2]{%
+     \ifthenelse{\equal{\axp at appendix}{strip}}{#2}{
+       \global\booltrue{axp at forward}%
+       \ifcsundef{axp at old@the\csname axp at cn@#1\endcsname}{%
+         \csletcs{axp at old@the\csname axp at cn@#1\endcsname}{the\csname axp at cn@#1\endcsname}%
+         \csletcs{theH\csname axp at cn@#1\endcsname}{the\csname axp at cn@#1\endcsname}%
+         \csdef{the\csname axp at cn@#1\endcsname}{%
+           \protect\axp at forward@link{axp at fw@r\roman{axp at rpcounter}}%
+             {\csname axp at old@the\csname axp at cn@#1\endcsname\endcsname}%
+         }%
+       }{}%
+       #2%
+       \ifcsdef{axp at old@the\csname axp at cn@#1\endcsname}{%
+         \csletcs{the\csname axp at cn@#1\endcsname}{axp at old@the\csname axp at cn@#1\endcsname}%
+       }{}%
+       \global\boolfalse{axp at forward}
+     }}%
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\axp at forward@link}
+% \begin{macro}{axp at forward}
+% Dummy macro, for handling the unwanted change of
+% the |\newlabel| entry in the |.aux| file caused by
+% changing the definition of |\thefoobar|.
+% 
+%    \begin{macrocode}
+  \newbool{axp at forward}
+  \newcommand{\axp at forward@link}[2]{%
+    \ifbool{axp at forward}{%
+      \ifcsdef{hyperlink}{%
+        \hyperlink{#1}{#2}%
+      }{%
+        #2%
+      }%
+    }{%
+      #2%
+    }%
+  }%
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% 
+% \begin{macro}{\axp at forward@target}
+% Provides the needed |\hypertarget|.
+% Intended to be written to the |.axp| file.
+%    \begin{macrocode}
+  \newcommand{\axp at forward@target}[2]{%
+    \ifcsname hypertarget\endcsname
+      \hypertarget{#1}{#2}%
+    \else
+      #2%
+    \fi
+  }
+%    \end{macrocode}
+% \end{macro}
+% 
+% \begin{macro}{\axp at forward@setup}
+% In order to support counter inheritance with the first
+% optional argument of |\newtheoremrep|,
+% we need access to the name of the counter.
+% For compliance with the behavior of |\@axp at newtheorem|,
+% the first optional argument (|#2|) is ignored
+% if the second optional argument (|#4|) is given.
+%    \begin{macrocode}
+  \newcommand{\axp at forward@setup}[4]{%
+    \csedef{axp at cn@#1}{\ifblank{#4}{\ifblank{#2}{#1}{#2}}{#1}}%
+  }
+%    \end{macrocode}
+% \end{macro}
+% 
+% 
 %    \subsubsection{Proof Environments}  
 % \begin{macro}{\noproofinappendix}
 %   Utility macro that toggles |axp at seenreptheorem| to false.
@@ -924,7 +1138,7 @@
   \newcommand\noproofinappendix{%
     \global\togglefalse{axp at seenreptheorem}%
   }
-%    \end{macrocode}  
+%    \end{macrocode}
 % \end{macro}
 % \begin{environment}{appendixproof}
 % We dump the content of this in appendix, within an original |proof|
@@ -1015,28 +1229,32 @@
 % \end{macro}  
 % \begin{macro}{\axp at oldsection}
 % \begin{macro}{\section}
+% \changes{v1.1.0}{2018/07/25}{Rewrote definition of \cs{section}
+% to enable optional argument. See \#23. (K. D. Bauer)}
+% \changes{v1.1.0}{2018/07/25}{Fix handling of fragile macros within
+% section headings. See \#22.}
 % \begin{macro}{\@section}
 % \begin{macro}{\@@section}
 % We redefine the |\section| command to create a label based on
-% |axp at seccounter| and to store its title in |\axp at sectitle|. Two definitions are necessary to cover the
-% starred and unstarred use of |\section|, though most likely the former
-% is not going to be used (since no section number will appear to refer
-% to that section in the appendix).
+% |axp at seccounter| and to store its title in |\axp at sectitle|.
+% In order to support starred and unstarred versions, as well
+% as the optional short-title argument, the intermediate macros
+% \cs{@section} and \cs{@@section} are needed.
 %    \begin{macrocode}
   \let\axp at oldsection\section
   \def\section{\@ifstar\@section\@@section}
-  \def\@section#1{%
-    \global\edef\axp at sectitle{#1}%
-    \axp at oldsection*{#1}%
+  \newcommand{\@section}[2][\relax]{\axp@@@section{*}{#1}{#2}}%
+  \newcommand{\@@section}[2][\relax]{\axp@@@section{}{#1}{#2}}%
+  \newcommand{\axp@@@section}[3]{%
+    \global\def\axp at sectitle{#3}%
+    \ifx\relax#2\relax
+      \axp at oldsection#1{#3}%
+    \else
+      \axp at oldsection#1[{#2}]{#3}%
+    \fi
     \addtocounter{axp at seccounter}{1}%
     \label{axp at s\roman{axp at seccounter}}%
   }
-  \def\@@section#1{%
-    \global\edef\axp at sectitle{#1}%
-    \axp at oldsection{#1}%
-    \addtocounter{axp at seccounter}{1}%
-    \label{axp at s\roman{axp at seccounter}}%
-  }
 %    \end{macrocode}  
 % \end{macro}
 % \end{macro}
@@ -1054,19 +1272,38 @@
 % \begin{macro}{\axp at writesection}
 % If |\axp at sectitle| is not empty, we create
 % a new section in the appendix, referring to the main text section.
+% 
+% Here, we wrap |\ref{axp at si}| into |\axp at protectref@i|, in order
+% to protect the label name from wrongly being converted to uppercase,
+% e.g., in \textsf{fancyhdr} with |\pagestyle{fancy}|.
+% 
+% This macro is defined both in the |.aux| file (in order to ensure availability
+% when typesetting the |\tableofcontents|), and immediately before typesetting
+% the appendix section (to ensure availability in the |\section| command).
+% 
 % \changes{v1.0.6}{2018/05/10}{Fix extraneous space after section number
 % in appendix titles}
+% \changes{v1.1.0}{2018/07/09}{Make \cs{axp at tmp} wrapper more robust.
+% Resolves issues from use of section title in \textsf{fancyhdr}, 
+% and in \cs{tableofcontents} (K. D. Bauer).}
 %    \begin{macrocode}  
   \newcommand\axp at writesection{%
     \ifx\axp at sectitle\@empty
     \else
+      \edef\axp at tmp{%
+        \noexpand\global\noexpand\def
+        \expandonce{\csname axp at protectref@\roman{axp at seccounter}\endcsname}{%
+          \noexpand\ref{axp at s\roman{axp at seccounter}}%
+        }%
+      }%
+      \immediate\write\@auxout{\expandonce\axp at tmp}
       \immediate\write\axp at proofsfile{%
-        \noexpand\def\noexpand\axp at tmp{%
-          \noexpand\ref{axp at s\roman{axp at seccounter}}%
-        }
+        \expandonce\axp at tmp^^J%
         \noexpand\axp at section{%
-          \noexpand\appendixsectionformat{\protect\noexpand\axp at tmp}%
-                                         {\axp at sectitle}%
+          \noexpand\appendixsectionformat{%
+            \protect
+            \expandonce{\csname axp at protectref@\roman{axp at seccounter}\endcsname}%
+          }{\expandonce\axp at sectitle}%
         }%
       }%
       \nosectionappendix
@@ -1074,6 +1311,20 @@
   }
 %    \end{macrocode}  
 % \end{macro}
+% Finally, in a somewhat ad hoc manner, we disable the whole section management
+% for \cs{tableofcontents}, which may be typeset using a section heading,
+% but for which automatic section management does not make sense.
+%   
+% \begin{macro}{\axp at oldtableofcontents}
+% \begin{macro}{\tableofcontents}
+% \changes{v1.1.0}{2018/07/09}{Disable section management for table
+% of contents}
+%    \begin{macrocode}  
+  \let\axp at oldtableofcontents\tableofcontents
+  \def\tableofcontents{{\let\section\axp at oldsection\axp at oldtableofcontents}}
+%    \end{macrocode}  
+% \end{macro}
+% \end{macro}
 %    \subsubsection{Append Compilation Mode}  
 %    \begin{macrocode}  
   \ifthenelse{\equal{\axp at appendix}{append}}{
@@ -1171,23 +1422,8 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
-% \begin{macro}{\section}
-% \begin{macro}{\@@section}
-% These document classes redefine |\section| in a weird way, adding
-% the possibility of an optional argument. We redefine them in a sane
-% way.    
+% 
 %    \begin{macrocode}
-    \def\section{\@ifstar\@section{\@dblarg{\@@section}}}
-    \def\@@section[#1]#2{%
-      \global\edef\axp at sectitle{#2}%
-      \axp at oldsection{#2}%
-      \addtocounter{axp at seccounter}{1}%
-      \label{axp at s\roman{axp at seccounter}}%
-    }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%    \begin{macrocode}
   \fi
 %    \end{macrocode}
 % \paragraph{ACM Document Classes (new version)}
@@ -1233,12 +1469,12 @@
 %    \begin{macrocode}
   \fi
 %    \end{macrocode}
-% \paragraph{\textsf{llncs} and other Springer document classes}
+% \paragraph{\textsf{llncs}}
 %    \begin{macrocode}
   \@ifclassloaded{llncs}{
 %    \end{macrocode}
 % \begin{macro}{proofsketch}
-% We first redefine the |proofsketch| environment, which is used
+% We redefine the |proofsketch| environment, which is used
 % differently in the base class.    
 %    \begin{macrocode}
     \renewenvironment{proofsketch}{\begin{axp at oldproof}[sketch]}{\end{axp at oldproof}}

Modified: trunk/Master/texmf-dist/tex/latex/apxproof/apxproof.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/apxproof/apxproof.sty	2018-08-08 21:05:58 UTC (rev 48376)
+++ trunk/Master/texmf-dist/tex/latex/apxproof/apxproof.sty	2018-08-08 21:06:12 UTC (rev 48377)
@@ -27,7 +27,7 @@
 %% 
 \NeedsTeXFormat{LaTeX2e}[2005/12/01]
 \ProvidesPackage{apxproof}
-  [2018/05/10 v1.0.6 Automatic proofs in appendix]
+  [2018/08/08 v1.1.0 Automatic proofs in appendix]
 \RequirePackage{bibunits}
 \RequirePackage{environ}
 \RequirePackage{etoolbox}
@@ -53,6 +53,7 @@
 }
 \DeclareStringOption[append]{appendix}
 \DeclareStringOption[separate]{bibliography}
+\DeclareStringOption[same]{repeqn}
 \ProcessLocalKeyvalOptions*
 \ifthenelse{\equal{\axp at appendix}{append}}{
   \message{apxproof: Appendix material appended to the document}
@@ -61,7 +62,7 @@
 }{\ifthenelse{\equal{\axp at appendix}{inline}}{
   \message{apxproof: Appendix material inlined within the document}
 }{
-  \errmessage{Error: unsupported option appendix=\axp at appendix for
+  \errmessage{Error: unsupported option appendix=\axp at appendix\ for
   package apxproof}
 }}}
 \ifthenelse{\equal{\axp at bibliography}{separate}}{
@@ -69,9 +70,17 @@
 }{\ifthenelse{\equal{\axp at bibliography}{common}}{
   \message{apxproof: Common bibliography for appendix and main text}
 }{
-  \errmessage{Error: unsupported option bibliography=\axp at bibliography for
+  \errmessage{Error: unsupported option bibliography=\axp at bibliography\ for
   package apxproof}
 }}
+\ifthenelse{\equal{\axp at repeqn}{same}}{
+  \message{apxproof: Repeated equations keep the same numbering}
+}{\ifthenelse{\equal{\axp at repeqn}{independent}}{
+  \message{apxproof: Repeated equations are independently numbered}
+}{
+  \errmessage{Error: unsupported option repeqn=\axp at repeqn\ for
+  package apxproof}
+}}
 \def\axp at newtheorem{\@ifstar\@@axp at newtheorem\@axp at newtheorem}
 \def\@axp at newtheorem#1#2#3#4{%
   \ifx\relax#4\relax
@@ -99,9 +108,29 @@
 \newcommand{\appendixbibliographystyle}{alpha}
 \newcommand{\appendixbibliographyprelim}{}
 \newcommand{\appendixprelim}{\clearpage\onecolumn}
-\newcommand{\appendixsectionformat}[2]{Proofs for Section~#1 (#2)}
+\newcommand{\appendixsectionformat}[2]{Proofs for Section~#1\ (#2)}
   \let\axp at oldproof\proof
   \let\endaxp at oldproof\endproof
+  \newcommand{\axp at redefinelabels}{%
+    \providecommand\label at in@display{}
+    \ifthenelse{\equal{\axp at appendix}{inline}}{
+      \let\axp at oldlabel\label
+      \let\axp at oldlabel@in at display\label at in@display
+      \renewcommand\label[1]{%
+        \axp at oldlabel{##1}%
+        \axp at oldlabel{##1-apx}%
+      }%
+      \renewcommand\label at in@display[1]{%
+        \axp at oldlabel@in at display{##1}%
+        \axp at oldlabel{##1-apx}%
+      }%
+    }{%
+      \let\axp at oldlabel\label
+      \let\axp at oldlabel@in at display\label at in@display
+      \renewcommand\label[1]{\axp at oldlabel{##1-apx}}%
+      \renewcommand\label at in@display[1]{\axp at oldlabel@in at display{##1-apx}}%
+    }%
+  }
    \ifdefined\spnewtheorem
 \def\@axp at newtheorem#1#2#3#4{%
   \ifx\relax#4\relax
@@ -129,7 +158,7 @@
     \expandafter\let\csname c@#1\endcsname\undefined
     \axp at newtheorem{#1}{#2}{#3}{#4}%
     \NewEnviron{#1rep}[1][]{%
-      \begin{#1}[##1]\BODY\end{#1}%
+      \begin{#1}[##1]\axp at redefinelabels\BODY\end{#1}%
     }
   }
   \let\inlineproof\proof
@@ -143,14 +172,18 @@
   \let\nosectionappendix\relax
 }
 {
-  \newwrite\axp at proofsfile
-  \immediate\openout\axp at proofsfile=\jobname.axp
-  \immediate\write\axp at proofsfile{%
-    \noexpand\makeatletter
-    \noexpand\let\noexpand\proof\noexpand\axp at oldproof
-    \noexpand\let\noexpand\endproof\noexpand\endaxp at oldproof
-    \noexpand\let\noexpand\section\noexpand\axp at oldsection
+  \AtBeginDocument{
+    \newwrite\axp at proofsfile
+    \immediate\openout\axp at proofsfile=\jobname.axp
   }
+  \AtBeginDocument{
+    \immediate\write\axp at proofsfile{%
+      \noexpand\makeatletter
+      \noexpand\let\noexpand\proof\noexpand\axp at oldproof
+      \noexpand\let\noexpand\endproof\noexpand\endaxp at oldproof
+      \noexpand\let\noexpand\section\noexpand\axp at oldsection
+    }
+  }
   \def\FVB at VerbatimOut{%
     \@bsphack
     \begingroup
@@ -168,6 +201,8 @@
     {\endVerbatimOut}
   \newtoggle{axp at seenreptheorem}
   \newcounter{axp at rpcounter}
+  \newcounter{axp at equation}
+  \newcounter{axp at equationx}
   \def\axp at newtheoremrep#1[#2]#3[#4]{%
     \expandafter\let\csname #1\endcsname\undefined
     \expandafter\let\csname c@#1\endcsname\undefined
@@ -174,12 +209,16 @@
     \axp at newtheorem{#1}{#2}{#3}{#4}%
     \expandafter\pretocmd\csname #1\endcsname{\noproofinappendix}{}{}%
     \axp at newtheorem*{axp@#1rp}{#3}%
+    \axp at forward@setup{#1}{#2}{#3}{#4}%
     \NewEnviron{#1rep}[1][]{%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \setcounter{axp at equation}{\value{equation}}%
+      }{}%
       \addtocounter{axp at rpcounter}{1}%
       \ifx\relax##1\relax
-        \begin{#1}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
+        \axp at with@forward{#1}{\begin{#1}}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
       \else
-        \begin{#1}[##1]\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
+        \axp at with@forward{#1}{\begin{#1}[##1]}\label{axp at r\roman{axp at rpcounter}}\BODY\end{#1}%
       \fi
       \global\toggletrue{axp at seenreptheorem}%
       \global\expandafter\let\csname rplet\roman{axp at rpcounter}%
@@ -186,17 +225,69 @@
                              \endcsname
       \BODY
       \axp at writesection%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \immediate\write\axp at proofsfile{%
+          \noexpand\setcounter{axp at equationx}{\value{equation}}%
+          \noexpand\setcounter{equation}{\theaxp at equation}%
+        }%
+      }{}%
       \immediate\write\axp at proofsfile{%
         \noexpand\begin{axp@#1rp}
           [\noexpand\ref{axp at r\roman{axp at rpcounter}}%
            \@ifnotempty{##1}{ \unexpanded{##1}}]%
-          \noexpand\let\noexpand\label\noexpand\@gobble%
+          \noexpand\axp at forward@target{axp at fw@r\roman{axp at rpcounter}}{}%
+          \noexpand\axp at redefinelabels
           \expandafter\noexpand\csname rplet\roman{axp at rpcounter}%
                                \endcsname
         \noexpand\end{axp@#1rp}
-      }
-    }
+      }%
+      \ifthenelse{\equal{\axp at repeqn}{same}}{%
+        \immediate\write\axp at proofsfile{%
+          \noexpand\setcounter{equation}{\value{axp at equationx}}%
+        }%
+      }{}%
+    }%
   }
+
+   \newcommand{\axp at with@forward}[2]{%
+     \ifthenelse{\equal{\axp at appendix}{strip}}{#2}{
+       \global\booltrue{axp at forward}%
+       \ifcsundef{axp at old@the\csname axp at cn@#1\endcsname}{%
+         \csletcs{axp at old@the\csname axp at cn@#1\endcsname}{the\csname axp at cn@#1\endcsname}%
+         \csletcs{theH\csname axp at cn@#1\endcsname}{the\csname axp at cn@#1\endcsname}%
+         \csdef{the\csname axp at cn@#1\endcsname}{%
+           \protect\axp at forward@link{axp at fw@r\roman{axp at rpcounter}}%
+             {\csname axp at old@the\csname axp at cn@#1\endcsname\endcsname}%
+         }%
+       }{}%
+       #2%
+       \ifcsdef{axp at old@the\csname axp at cn@#1\endcsname}{%
+         \csletcs{the\csname axp at cn@#1\endcsname}{axp at old@the\csname axp at cn@#1\endcsname}%
+       }{}%
+       \global\boolfalse{axp at forward}
+     }}%
+  \newbool{axp at forward}
+  \newcommand{\axp at forward@link}[2]{%
+    \ifbool{axp at forward}{%
+      \ifcsdef{hyperlink}{%
+        \hyperlink{#1}{#2}%
+      }{%
+        #2%
+      }%
+    }{%
+      #2%
+    }%
+  }%
+  \newcommand{\axp at forward@target}[2]{%
+    \ifcsname hypertarget\endcsname
+      \hypertarget{#1}{#2}%
+    \else
+      #2%
+    \fi
+  }
+  \newcommand{\axp at forward@setup}[4]{%
+    \csedef{axp at cn@#1}{\ifblank{#4}{\ifblank{#2}{#1}{#2}}{#1}}%
+  }
   \newcommand\noproofinappendix{%
     \global\togglefalse{axp at seenreptheorem}%
   }
@@ -245,18 +336,18 @@
   }
   \let\axp at oldsection\section
   \def\section{\@ifstar\@section\@@section}
-  \def\@section#1{%
-    \global\edef\axp at sectitle{#1}%
-    \axp at oldsection*{#1}%
+  \newcommand{\@section}[2][\relax]{\axp@@@section{*}{#1}{#2}}%
+  \newcommand{\@@section}[2][\relax]{\axp@@@section{}{#1}{#2}}%
+  \newcommand{\axp@@@section}[3]{%
+    \global\def\axp at sectitle{#3}%
+    \ifx\relax#2\relax
+      \axp at oldsection#1{#3}%
+    \else
+      \axp at oldsection#1[{#2}]{#3}%
+    \fi
     \addtocounter{axp at seccounter}{1}%
     \label{axp at s\roman{axp at seccounter}}%
   }
-  \def\@@section#1{%
-    \global\edef\axp at sectitle{#1}%
-    \axp at oldsection{#1}%
-    \addtocounter{axp at seccounter}{1}%
-    \label{axp at s\roman{axp at seccounter}}%
-  }
   \newcommand{\nosectionappendix}{
     \global\def\axp at sectitle{}%
   }
@@ -263,18 +354,27 @@
   \newcommand\axp at writesection{%
     \ifx\axp at sectitle\@empty
     \else
+      \edef\axp at tmp{%
+        \noexpand\global\noexpand\def
+        \expandonce{\csname axp at protectref@\roman{axp at seccounter}\endcsname}{%
+          \noexpand\ref{axp at s\roman{axp at seccounter}}%
+        }%
+      }%
+      \immediate\write\@auxout{\expandonce\axp at tmp}
       \immediate\write\axp at proofsfile{%
-        \noexpand\def\noexpand\axp at tmp{%
-          \noexpand\ref{axp at s\roman{axp at seccounter}}%
-        }
+        \expandonce\axp at tmp^^J%
         \noexpand\axp at section{%
-          \noexpand\appendixsectionformat{\protect\noexpand\axp at tmp}%
-                                         {\axp at sectitle}%
+          \noexpand\appendixsectionformat{%
+            \protect
+            \expandonce{\csname axp at protectref@\roman{axp at seccounter}\endcsname}%
+          }{\expandonce\axp at sectitle}%
         }%
       }%
       \nosectionappendix
     \fi
   }
+  \let\axp at oldtableofcontents\tableofcontents
+  \def\tableofcontents{{\let\section\axp at oldsection\axp at oldtableofcontents}}
   \ifthenelse{\equal{\axp at appendix}{append}}{
     \let\axp at oldbibliography\bibliography
     \renewcommand\bibliography[1]{%
@@ -320,13 +420,6 @@
     \patchcmd{\thebibliography}{References}{\protect\refname}{}{}
     \newcommand{\refname}{REFERENCES}
     \renewcommand{\appendixrefname}{REFERENCES FOR THE APPENDIX}
-    \def\section{\@ifstar\@section{\@dblarg{\@@section}}}
-    \def\@@section[#1]#2{%
-      \global\edef\axp at sectitle{#2}%
-      \axp at oldsection{#2}%
-      \addtocounter{axp at seccounter}{1}%
-      \label{axp at s\roman{axp at seccounter}}%
-    }
   \fi
   \@ifclassloaded{acmart}{
   \newtheoremstyle{mystyle}



More information about the tex-live-commits mailing list