[Tex/LaTex] Vertical position after navigating to hyperref hypertargets from hyperlinks seems too low

hyperreflinkspdf

The vertical scroll position after navigating to a \hypertarget from a \hyperlink (described in the hyperref manual) seems to be too low. The scroll position is at the baseline of the \hypertarget, so the target cannot be seen after clicking a \hyperlink.

If I run latex -output-format pdf document.tex twice on Mac OS X 10.8.2 to create a PDF from this document—

\documentclass{minimal}
\usepackage[colorlinks=true,raiselinks=true]{hyperref}
\usepackage{lipsum}
\begin{document}
\hyperlink{target1}{target1}
\hyperlink{target2}{target2}
%\hyperlink{target3}{target3}
\par\lipsum[1-7]
\lipsum*[8]
\hypertarget{target1}{target1}
\makeatletter\Hy@raisedlink{\hypertarget{target2}{target2}}\makeatother
%\raisebox{\ht\strutbox}{\hypertarget{target3}{target3}}
\end{document}

—all the \hyperlinks in the resulting document navigate to the baselines of their respective \hypertargets.

The example using \Hy@raisedlink is taken from hypertarget seems to aim a line too low. The example using \raisebox is taken from the same question, but I’ve commented it out because it shows different (but still unexpected) behavior.

This question is related to Certain hyperlinks (memoir+hyperref) placed too low and hypertarget seems to aim a line too low, but I am asking it as a new question because I am not using memoir, and neither of the solutions described in hypertarget seems to aim a line too low seem to work for me.

This issue seems to be the very thing that the hyperref option raiselinks is intended to address, but that option appears to have no effect on the example document.

How should one make a \hypertarget (or equivalent) that is above the baseline?

One could, I suppose, use \Hy@raisedlink with an empty \hypertarget (that is, a \hypertarget with no associated text), but I’m hoping there’s a better way.

Best Answer

The baseline is well known in TeX, but not the height of the current line. Only TeX knows this at a later time, after paragraph breaking. Measuring the height via boxing looses line breaking. \vadjust pre of pdfTeX was (is?) not stable enough, some circumstances causes segmentation faults. To some degree LuaTeX's attributes might help at the cost of a complete different non-trivial implementation. Back to the question, the current workaround is already mentioned (e.g. \Hy@raisedlink with empty \hypertarget).

Related Question