# What to do with this hyperref note on amsmath?

http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/ has this note copied below:

amsmath
-------------
The environments equation and eqnarray are not supported too well. For example, there might be spacing problems (eqnarray isn't recommended anyway, see CTAN:info/l2tabu/, the situation for equation is unclear, because nobody is interested in investigating). Consider using the environments that package amsmath provide, e.g. gather for equation. The environment equation can even redefined to use gather:

\usepackage{amsmath}
\let\equation\gather
\let\endequation\endgather


However, gather and equation environment have the spacing difference as in the answer by Will in align vs equation. Thus my question:

In a document using both hyperref and amsmath, what is the best replacement for equation?

-
@ShreevatsaR I carefully check this with texlive 2009. Are you seeing something different? –  Leo Liu Aug 4 '10 at 8:21

You can see a spacing problem with the following example. The two equations have different spacing with hyperref, but the same spacing (as they should) without it:

\documentclass[fleqn]{article}

\usepackage{amsmath}
\usepackage{hyperref}

\begin{document}

This is a test to check the spacing of the equation environment. Too much?
$$a=b$$
This is a test to check the spacing of the equation environment.

This is a test to check the spacing of the equation environment. Too much?%
$$a=b$$
This is a test to check the spacing of the equation environment.

\end{document}


But this problem is imo not enough to stop using the equation environment. The other math environments produce too much space if the sentence before the displayed math is short:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

This is a test to check the spacing of the equation environment. Too much? Foo.
$$a=b$$
This is a test to check the spacing of the equation environment.

This is a test to check the spacing of the align environment. Too much? Foo.
\begin{align}$$a=b$$\end{align}
This is a test to check the spacing of the align environment.

\end{document}


which is a much more common problem.

-
If you compile the top example with pdflatex you will see a difference in spacing if you compile with and without hyperref. –  Martin Heller Aug 5 '10 at 21:07
Oh I see! Thank you. So do you think adding a % is good enough to fix the spacing issue? –  ShreevatsaR Aug 5 '10 at 21:19
No, the percent was just to prevent triggering the problem in this specific case. Not a general fix. But you can fabricate other examples where adding hyperref changes the way text is typeset. That is not specific to the equation environment. However, I think the benefits of using the equation environment for single displayed equations outweigh the the slight risk of running into this kind of spacing modifications caused be hyperref. –  Martin Heller Aug 5 '10 at 21:54
@Martin: thank you for the great answer. It seems the note on hyperref needs some update. Is this bug in hyperref or amsmath? –  Leo Liu Aug 6 '10 at 4:32
Thanks. For now I'll continue using equation ;) –  Leo Liu Aug 6 '10 at 17:54

i'm writing on behalf of the maintainers of amsmath. we do maintain a list of bugs reported for both amsmath and friends and the ams document classes, and are now actively examining the list in preparation for an upgrade of the entire collection.

the spacing problem mentioned in this thread appears to be a bug, though not identical to any that have already been reported (a vertical spacing mismatch between equation and multline is on our list), so this example will be examined and added to the list if verified.

for bugs to be considered in upgrades or overhauls of amsmath, please report them to tech-support@ams.org

-
This vertical spacing problem is not a bug in the amsmath package. It is related to the way the equation environment is redefined by the hyperref package in case of the fleqn option being set. By the way, the answer providing a patch that tries to fix this spacing problem had been posted by me before I became a registered user. –  mhp Aug 23 '11 at 19:42
@mhp -- thanks, good information. we'll put it on our list to look into anyway; maybe we can set a trap for hyperref. –  barbara beeton Aug 24 '11 at 12:50

Put the following code somewhere in your document preamble:

\makeatletter
\AtBeginDocument{%
\if@fleqn%
\let\old@equation\equation%
\renewcommand{\equation}{\ifhmode\unskip\fi\old@equation}%
\fi%
}
\makeatother


This should fix the vertical spacing problem that arises when using AMSLaTeX's equation environment together with the hyperref package.

-

My rule of thumb is to always use align everywhere for math. Works with hyperref just fine =)

To suppress too much whitespace do not place a double carridge-return after the environment.

bla:
\begin{align}
a^2+b^2=c^2
\end{align}
More text straight away

-
The spacing difference is between text and the following equation. –  Leo Liu Aug 5 '10 at 6:39
If you have blank line after bla there will be more space. This way there is "little" space. This is subjective of course. –  Dima Aug 5 '10 at 10:43
It looks like you haven't tried the test file provided by Will Robertson or you failed to notice the difference. 'hello' is further away from equations produced by align than equation`. –  Leo Liu Aug 5 '10 at 12:30