Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefoot and postfoot hooks called twice with restate key #54

Open
mbertucci47 opened this issue Nov 12, 2023 · 1 comment
Open

prefoot and postfoot hooks called twice with restate key #54

mbertucci47 opened this issue Nov 12, 2023 · 1 comment

Comments

@mbertucci47
Copy link
Collaborator

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}

thmtestcode-1

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.

@mbertucci47
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant