1

Maybe this is related to Bad page break with \newenvironment, \refstepcounter and hyperref, but the answer there (insert \mbox{}) didn't help.

In the following code

\documentclass{article}
\RequirePackage{amsmath}
\RequirePackage{hyperref}
\newcounter{number}
\begin{document}
\begin{enumerate}
\item
\[a\]
\refstepcounter{number}
\item
\end{enumerate}
\end{document}

the line \refstepcounter{number} produces additional vertical space, which is not there, if I use \stepcounter{number} oder erase the hyperref Package. How can I avoid this space?

4
  • Why do you want to do the \refstepcounter exactly there? Commented Aug 5, 2019 at 10:26
  • @UlrikeFischer: The \refstepcounter is executed dozens of times via several nested macros. Just a few times it is "exactly there" (after the [...]). You mean it would be easiest to reorganize the macros such that \refstepcounter can never come directly after [...]?
    – Gerhard
    Commented Aug 5, 2019 at 14:20
  • Yes, it would be better if it is only executed in a place where the whatsits for the link anchor doesn't harm. Or if you disable anchors there. Commented Aug 5, 2019 at 14:27
  • Hm, I can't see how to reorganize it. The \refstepcounter is placed in something like \newenvironment{display}{}{\refstepcounter{number}}. It would not work at the beginning of the environment and I also cannot prevent the content of the (proof-like) environment from ending with a []. How could I 'disable anchors'?
    – Gerhard
    Commented Aug 5, 2019 at 14:41

1 Answer 1

3

You can use the original \refstepcounter. It won't insert a space, but also no anchor, so links will probably go to the wrong places:

\documentclass{article}
\RequirePackage{amsmath}
\RequirePackage{hyperref}
\newcounter{number}
\begin{document}

\begin{enumerate}
\item xxxxxxxxxxxxx 
\[aaaaaaaaaaa\]
\refstepcounter{number}
\item xxxxxxxxxxxx
\end{enumerate}

\begin{enumerate}
\item xxxxxxxxxxxxx 
\[aaaaaaaaaaaa\]
\csname H@refstepcounter\endcsname{number}
\item xxxxxxxxxxxxx
\end{enumerate}


\end{document}

enter image description here

1
  • I think it would be even better to save the original '\refstepcounter' via '\let\rsc\refstepcounter' before calling 'hyperref'. Then replace '\csname H@refstepcounter\endcsname{number}' by '\rsc{number}'.
    – Gerhard
    Commented Aug 14, 2019 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .