7

When the fleqn option is used, the vertical spacing before an equation placed right after a "long" text line (exactly \linewidth I would say) is improperly set up. See below:

enter image description here

From the mathmode user guide, this could probably be fixed through the \topsep length. Is it the right way to proceed? The problem is reproduced by the code below:

\documentclass[12pt,fleqn]{book}
\usepackage{amsmath}
\usepackage{hyperref}
\begin{document}
\chapter{plo}
\section{plo}
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaem oeiu eoiu eoiu oeee.
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaemm
\begin{equation}
\cos\pi=-1
\end{equation}
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaem oeiu eoiu eoiu oeee.
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùae
\begin{equation}
\cos\pi=-1
\end{equation}
\end{document}

There is something wrong involving hyperref, amsmath, and fleqn. Removing one of those removes the problem.

  • Please show an example document that produces the image. Are you using amsmath or default latex setting? – David Carlisle Jul 3 '13 at 21:52
  • Is there some relation with the fact that the line ends with :? – Sigur Jul 3 '13 at 21:59
  • 1
    Note that you should never leave empty lines around/between display equations and surrounding text. – Werner Jul 3 '13 at 22:03
  • @DavidCarlisle I just edited the message. – pluton Jul 3 '13 at 22:10
  • @Sigur No relation. – pluton Jul 3 '13 at 22:11
8

The last line before the first equation ends with a space. This is usually not a problem, because TeX ends the text before the displayed equation similar to a paragraph end. That means, the last space is removed and \parfillskip is added.

However, package hyperref has to insert whatsits somewhere at some time. It hooks into \refstepcounter, that is called right before displaying the equation to update the equation counter. hyperref uses this to add an anchor that is needed as link target, if the equation if referenced.

However, then the last space of the previous text cannot be removed, because the whatsit/anchor goes inbetween, hiding the space. Because the text fills the previous line, the result is a line break, followed by an invisible line with the anchor. The space is removed at the start of the new line, but the invisible line remains, consuming space.

As quick workaround, the space can be removed by a percent line:

...aemm%
\begin{equation}

Better is a fix that does remove the space automatically and fixes the position of the anchor, because the position at the end of the previous line is not a good place.

\documentclass[12pt,fleqn]{book}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\equation}{\incr@eqnum\mathdisplay@push}{%
  \ifhmode
    \unskip
    \vadjust{%
      \incr@eqnum
      \global\let\gfix@incr@eqnum\incr@eqnum
      \global\let\gfix@currentlabel\@currentlabel
      \global\let\gfix@currentHref\@currentHref
    }%
    \let\incr@eqnum\gfix@incr@eqnum
    \let\@currentlabel\gfix@currentlabel
    \let\@currentHref\gfix@currentHref
  \else
    \incr@eqnum
  \fi
  \mathdisplay@push
}{}{}
\makeatother

\begin{document}
\chapter{plo}
\section{plo}
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaem oeiu eoiu
eoiu oeee.
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaemm
\begin{equation}
\label{eq:first}
\cos\pi=-1
\end{equation}
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùaeoiuaem oeiu eoiu
eoiu oeee.
eoiu oieu oeiuoe ueoi ueoi ueoiu eoiu oeu oe iupaêio umùae
\begin{equation}
\label{eq:second}
\cos\pi=-1
\end{equation}
Equations \ref{eq:first} and \ref{eq:second}.
\end{document}

Result

  • 1
    +1 I was going to suggest adding an \ifhmode\unskip to equation as a workaround to save patching hyperref internals, but this is much better:-) – David Carlisle Jul 3 '13 at 23:26
  • Will this patch be included in a coming version of hyperref? – pluton Jul 4 '13 at 17:31
  • 1
    @pluton: It is on my ToDo list for hyperref. But other projects (e.g. release of my bundle) have currently more priority. – Heiko Oberdiek Jul 4 '13 at 21:15
  • perfectly fine. No pressure :) – pluton Jul 5 '13 at 0:35
  • 1
    for subequation, I took the solution from here: tex.stackexchange.com/a/27058/44467 – Faekynn Dec 28 '15 at 19:04

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.