thmtools
thmtools copied to clipboard
prefoot and postfoot hooks called twice with restate key
When a theorem is called with the restate
key, the prefoot and postfoot hooks are called twice. It only occurs with the key version, not the restatable
environment.
\documentclass{article}
\usepackage{amsthm,thmtools}
\declaretheorem{theorem}
\addtotheorempreheadhook{PREHEAD}
\addtotheorempostheadhook{POSTHEAD}
\addtotheoremprefoothook{PREFOOT}
\addtotheorempostfoothook{POSTFOOT}
\begin{document}
\begin{theorem}
body text
\end{theorem}
\begin{theorem}[restate=foo]
body text
\end{theorem}
\begin{restatable}{theorem}{blub}
body text
\end{restatable}
\end{document}
The hooks are also not duplicated in the restated theorem, so here \foo*
.
As a side observation, the restatable
environment adds an extra space between the posthead and body.
I think I see the issue but I don't know how to fix it. In the definition of the restate
key there is
\protected@edef\tmp@a{%
\@nx\thmt@thisistheonetrue
\@nx\def\@nx\@currenvir{\thmt@envname}%
\@nx\@xa\@nx\thmt@restatable\@nx\@xa[\@nx\thmt@storedoptargs]%
{\thmt@envname}{\thmt@storename}%
}%
\@xa\g@addto@macro\@xa\thmt@local@postheadhook\@xa{%
\tmp@a
}%
so I believe the prefoot and postfoot hooks are being collected along with the theorem body, then since \endtheorem
is defined with
\@xa\def\csname end#1\endcsname{%
% these need to be in opposite order of headhooks.
\csname thmt@generic@prefoothook\endcsname
\csname thmt@#1@prefoothook\endcsname
\csname thmt@local@prefoothook\endcsname
\csname thmt@original@end#1\endcsname
\csname thmt@generic@postfoothook\endcsname
\csname thmt@#1@postfoothook\endcsname
\csname thmt@local@postfoothook\endcsname
}%
in thm-patch.sty, the prefoot and postfoot hooks are executed once again. This can perhaps be fixed with a redefinition of \endtheorem
in the restate key, but I don't yet see how to stop \thmt@collect@body
from collecting the hooks.