muzimuzhi / thmtools

New home for LaTeX package bundle thmtools
LaTeX Project Public License v1.3c
16 stars 3 forks source link

too much space with restatable #40

Open mbertucci47 opened 10 months ago

mbertucci47 commented 10 months ago

The theorem printed by the restatable has extra vertical space above it. The same goes for the restated theorem from a restatable* (but not the restatable* itself). There is no issue with the restated theorems from a restatable environment or theorems using the restate key. Here's an example:

\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}

\declaretheorem{theorem}

\begin{document}

\begin{theorem}
\kant[2][1]
\end{theorem}

\begin{theorem}[restate=foo]
\kant[1][2]
\end{theorem}

\begin{theorem}
\kant[2][1]
\end{theorem}

\foo*

\begin{theorem}
\kant[2][1]
\end{theorem}

\begin{restatable}{theorem}{foobar}
\kant[1][3]
\end{restatable}

\begin{theorem}
\kant[2][1]
\end{theorem}

\foobar*

\begin{theorem}
\kant[2][1]
\end{theorem}

\begin{restatable*}{theorem}{blub}
\kant[1][4]
\end{restatable*}

\begin{theorem}
\kant[2][1]
\end{theorem}

\blub

\begin{theorem}
\kant[2][1]
\end{theorem}

\end{document}

document-1

Apologies for the length; I wanted to show all possible behaviors with normal theorems interspersed. The space above the restatable environment theorem and the restated \blub is too big.

mbertucci47 commented 10 months ago

A glance at the thm-restate code shows the issue is with the true branch of \ifthmt@thisistheone. A further glance shows the issue is in \thmt@rst@storecounters, called on line 119. I don't really know what I'm talking about but I think the \label{thmt@@#1@data} is inserting a "whatsit" that's adding the undesired space. If I comment it the space goes away

mbertucci47 commented 10 months ago

This TeXSE question shows how to fix this if hyperref is loaded. Redefining \thmt@rst@storecounters as

\def\thmt@rst@storecounters#1{%
  \bgroup
  \def\@currentlabel{}%
  \@for\thmt@ctr:=\thmt@innercounters\do{%
    \thmt@sanitizethe{\thmt@ctr}%
    \protected@edef\@currentlabel{%
      \@currentlabel
      \protect\def\@xa\protect\csname the\thmt@ctr\endcsname{%
        \csname the\thmt@ctr\endcsname}%
      \ifcsname theH\thmt@ctr\endcsname
        \protect\def\@xa\protect\csname theH\thmt@ctr\endcsname{%
          (restate \protect\theHthmt@dummyctr)\csname theH\thmt@ctr\endcsname}%
      \fi
      \protect\setcounter{\thmt@ctr}{\number\csname c@\thmt@ctr\endcsname}%
    }%
  }%
  \Hy@SaveLastskip
  \label{thmt@@#1@data}%
  \Hy@RestoreLastskip
  \egroup
}%

seems to work. Maybe thmtools can define its own versions of \Hy@SaveLastskip and \Hy@RestoreLastskip?