PierreSenellart / apxproof

LaTeX package for automatically putting proof environments in appendix
LaTeX Project Public License v1.3c
23 stars 8 forks source link

Appendix breaks fancyhdr due to use of \axp@tmp in .axp file #12

Closed kbauer closed 6 years ago

kbauer commented 6 years ago

The apxproof package is incompatible with \fancyhdr and \pagestyle{fancy}, causing an "Undefined command sequence" error upon typesetting the header.

The issue seems to be caused by the use of \axp@tmp in the .axp file, as by the time the header is typeset, including the section title, this macro may no longer be assigned.

Minimal working example

\documentclass[12pt]{article}

\usepackage{fancyhdr}
\usepackage{apxproof}

\newtheoremrep{thm}{Theorem}

\pagestyle{fancy}
\iftrue % -- Set to \iffalse to cause the error.
  \makeatletter
  \def\axp@tmp{\texttt{\string\axp@tmp=undefined}}
  \makeatother
\fi

\begin{document}

\section{First section.}

\begin{thmrep}
Hello world.
\end{thmrep}

\end{document}
PierreSenellart commented 6 years ago

This is actually roughly the same issue as #9, and due to a \protect use before issuing the \axp@tmp command. The problem is, if I do not protect it, some document classes behave stupidly (trying to uppercase the counter name in section headers). I need to take some time to think how to solve this issue in the cleanest way possible.

kbauer commented 6 years ago

Just to be clear: This means that putting the \ref directly in the \axp@section would yield undesirable results?

diff --git a/apxproof.dtx b/apxproof.dtx
index 02010c8..46afcf4 100644
--- a/apxproof.dtx
+++ b/apxproof.dtx
@@ -1165,12 +1165,10 @@ This is a citation in the appendix~\cite{proofsAreHard}.
     \ifx\axp@sectitle\@empty
     \else
       \immediate\write\axp@proofsfile{%
-        \noexpand\def\noexpand\axp@tmp{%
-          \noexpand\ref{axp@s\roman{axp@seccounter}}%
-        }
         \noexpand\axp@section{%
-          \noexpand\appendixsectionformat{\protect\noexpand\axp@tmp}%
-                                         {\axp@sectitle}%
+          \noexpand\appendixsectionformat{%
+            \protect\noexpand\ref{axp@s\roman{axp@seccounter}}%
+          }{\axp@sectitle}%
         }%
       }%
       \nosectionappendix
kbauer commented 6 years ago

Accidential close...

kbauer commented 6 years ago

Ah, I see... This ends up uppercasing the label of the reference.

LaTeX Warning: Reference `AXP@SIV' on page 3 undefined on input line 7.
kbauer commented 6 years ago

Having created a testfile

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{../../apxproof}
\makeatletter
\let\bibliography\@gobble
\let\bibliographystyle\@gobble
\makeatother
\input{../common}

I noticed, that the error only occurs when the last page is using \axp@tmp in the header, i.e. it is undefined by \end{document}: Without the \let\bilbiography[style]\relax the last header is the bibliography, and no error occurs.

I think, the solution may be as easy as adding \noexpand\global before \noexpand\def\noexpand\axp@tmp:

diff --git a/apxproof.dtx b/apxproof.dtx
index 02010c8..58a4bdd 100644
--- a/apxproof.dtx
+++ b/apxproof.dtx
@@ -1165,7 +1165,7 @@ This is a citation in the appendix~\cite{proofsAreHard}.
     \ifx\axp@sectitle\@empty
     \else
       \immediate\write\axp@proofsfile{%
-        \noexpand\def\noexpand\axp@tmp{%
+        \noexpand\global\noexpand\def\noexpand\axp@tmp{%
           \noexpand\ref{axp@s\roman{axp@seccounter}}%
         }
         \noexpand\axp@section{%
PierreSenellart commented 6 years ago

Thanks for the fix! Merged in 926c39b after minor corrections. This seems to solve most issues with fancyhdr and \tableofcontents.