6

This question already has an answer here:

When the length of the text prior to an equation environment approaches \textwidth, hyperref adds an extra vertical space, as illustrated by the following snapshot:

enter image description here

The corresponding code is

\documentclass[12pt,fleqn]{article}
\usepackage{a4}
\usepackage{amsmath}
\usepackage{hyperref}

\textwidth = 16cm
\setlength{\parskip}{1.5ex plus0.5ex minus0.5ex}
\setlength{\parindent}{0em}

\begin{document}
Suppose $\vec{T}$ is a lower triangular matrix. Then $\vec{T}^{T}$ is upper triangular. By Lemma 2.23921,
\begin{equation}
    \det(\vec{T}) = \det(\vec{T}^{T}) = [\vec{T}]_{11}[\vec{T}]_{22}\dotsb[\vec{T}]_{nn},
\end{equation}
as required.
\end{document}

Note that it seems to affect the equation environment only.

Since there is no apparent way to predetermine the occurrence the problem in the source code, I will have to manually scan the output text for the affected parts and replace equation with other math environments, such as gather, to circumvent the problem; clearly, this approach is suboptimal.

So, the question is, why does it only affect the equation environment but not other math environments? Is there a way fix this?

marked as duplicate by Werner spacing Mar 30 '15 at 14:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Welcome to TeX.SX! – Paul Gessler Mar 30 '15 at 1:21
  • That does not get you A4 paper, by the way. Add a4paper to the class options and remove the a4 package. Also, better to use \usepackage[textwidth=16cm]{geometry} to set layout dimensions. – cfr Mar 30 '15 at 1:25
  • not in a position to explore the code, but i do know that the equation environment is not defined the same way as that of the other amsmath enviroments. it was originally, but there were too many cries from users who wanted to be able to use a "shorthand" form \be ... \ee that it was reverted to the original latex (2.09) definition. – barbara beeton Mar 30 '15 at 1:27
  • Is the spacing issue similar to the one mentioned here? Does hyperref add anchors for equation but not the other maths environments? If you aren't using the anchors, you can load amsmath after hyperref to avoid the problem, I think. (From another question which I've currently lost track of.) – cfr Mar 30 '15 at 1:30
  • @cfr Switching the load order didn't work. Thanks for the heads up by the way. It looks like my template is way too outdated. – PYK Mar 31 '15 at 17:47
3

You're being unlucky, but also hyperref should do better.

\documentclass[12pt,a4paper,fleqn]{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage{hyperref}

\BeforeBeginEnvironment{equation}{%
  \ifhmode\unskip\fi
}

\textwidth = 16cm
\setlength{\parskip}{1.5ex plus0.5ex minus0.5ex}
\setlength{\parindent}{0em}

\begin{document}

Suppose $\vec{T}$ is a lower triangular matrix. Then $\vec{T}^{T}$ is upper
triangular. By Lemma 2.23921,
\begin{equation}
    \det(\vec{T}) = \det(\vec{T}^{T}) = [\vec{T}]_{11}[\vec{T}]_{22}\dotsb[\vec{T}]_{nn},
\end{equation}
as required.

\end{document}

enter image description here

Note. I left your setting of \parindent and \parskip, but this doesn't mean I endorse them. To the contrary, I advice you not to use those settings.

  • ...a duplicate of fleqn option and long text lines. – Werner Mar 30 '15 at 14:10
  • @egreg Thank you for the simple and yet effective solution. Also, I appreciate your advice regarding my layout settings. I have since opted for \usepackage{parskip} to have the style of having no indentation with space between paragraphs. It makes me wonder if it is possible to have my 300+ lines of preamble corrected. – PYK Mar 31 '15 at 17:58
1

It seems that this is a bug in the hyperref package. When hyperref isn't loaded then the paragraph-part before display is ended by a space (after the comma at the end of the line in your excellent example) and then the \begin{equation} does \refstepcounter {equation} and then it expands to $$ which starts the display mode. The start of display mode executes TeX internal algorithm: it finalizes the current horizontal mode by \unskip (i.e. the mentioned space is removed) and does something similar like \par (i.e. the horizontal list is broken to the lines, horizontal mode is interrupted and the lines are contributed to the vertical list). Then the display math is typeset. Note, that this case (without the ending space in the horizontal mode, because it is removed) fits the paragraph-part exactly to one line.

When hyperref is loaded, it re-defines the \refstepcounter macro. Now, this macro advances the counter by one plus puts the hyperlink destination to the current mode. This current mode is horizontal mode and the destination is put after the mentioned space. This destination is realized by \penalty10000\hbox{...\pdfdest{...}} but this isn't important. The main result is that the internal \unskip action processed when display math is started cannot remove the mentioned space because there is a barrier in the form of hyperlink destination. And the horizontal mode is longer by the mentioned space in this case. Now, this horizontal list is broken to the two lines (the second line is empty) and after that, the display math is typeset.

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