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?

  • Why do you want to do the \refstepcounter exactly there? – Ulrike Fischer Aug 5 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 Aug 5 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. – Ulrike Fischer Aug 5 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 Aug 5 at 14:41
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

  • 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 Aug 14 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.