21

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?

1
  • @ShreevatsaR I carefully check this with texlive 2009. Are you seeing something different?
    – Leo Liu
    Commented Aug 4, 2010 at 8:21

4 Answers 4

15

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?
\begin{equation}
a=b
\end{equation}
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?%
\begin{equation}
a=b
\end{equation}
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.
\begin{equation}
a=b
\end{equation}
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.

7
  • 1
    If you compile the top example with pdflatex you will see a difference in spacing if you compile with and without hyperref. Commented Aug 5, 2010 at 21:07
  • Oh I see! Thank you. So do you think adding a % is good enough to fix the spacing issue? Commented Aug 5, 2010 at 21:19
  • 2
    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. Commented Aug 5, 2010 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
    Commented Aug 6, 2010 at 4:32
  • 1
    Thanks. For now I'll continue using equation ;)
    – Leo Liu
    Commented Aug 6, 2010 at 17:54
24

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.

Update:

Maintenance of this package was transferred to the LaTeX Project team in 2016. Bug reports can be opened (category amslatex) at https://latex-project.org/bugs/.

2
  • 1
    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
    Commented Aug 23, 2011 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. Commented Aug 24, 2011 at 12:50
3

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.

0
0

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
3
  • The spacing difference is between text and the following equation.
    – Leo Liu
    Commented Aug 5, 2010 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
    Commented Aug 5, 2010 at 10:43
  • 4
    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
    Commented Aug 5, 2010 at 12:30

You must log in to answer this question.

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