hyperref
hyperref copied to clipboard
Way too normal size of references in stackrel when running `latex`
Consider the code
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[hidelinks]{hyperref}
\begin{document}
\newtheorem{thm}{Theorem}
\begin{thm}\label{BC}B=C.\end{thm}
\LinesNumbered
\begin{algorithm}
A:=B\nllabel{lineFoo}\;
\end{algorithm}
$A\stackrel{\mathrm{line}\ \ref{lineFoo}}{=}B\stackrel{\mathrm{Thm.}\ \ref{BC}}{=}C$.
\end{document}
When running latex
on it, the resulting dvi file has normal-sized labels 1
, while the labels should be, in fact, small-sized.
Later, when dvi is translated to postscript or to pdf, the normal size of 1
is maintained, resulting in an unpleasant output. (Remark: when running pdflatex
, the size is small as expected.)
Thanks for repairing in advance!
er yes this is \pdf@rect
in pdfmark.def.
This needs to box things to measure them and make the rectangle coordinates for the link. measuring boxes in math mode is notoriously difficult in TeX as (because of the $ a \outer b $
primitive syntax). You never know what size anything is at the point that you typeset the box. The situation here has the extra complication that to support the breaklinks option the box is sometimes unboxed. Within stackrel (or any kind of superscript) breaking is not an issue, but again the facilities offered by the tex primitives don't really help and so the code for breaklinks would still unbox here even though linebreaking is not a possibility.
That said it may be possible to do something but in the meantime I offer this workaround
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[hidelinks]{hyperref}
\usepackage{amsmath}
\begin{document}
\newtheorem{thm}{Theorem}
\begin{thm}\label{BC}B=C.\end{thm}
\LinesNumbered
\begin{algorithm}
A:=B\nllabel{lineFoo}\;
\end{algorithm}
$A\stackrel{\mathrm{line}\ \text{\ref{lineFoo}}}{=}B\stackrel{\mathrm{Thm.}\ \ref{BC}}{=}C$.
\end{document}
Wrapping the link in \text{\ref{...}}
(or potentially \text{$\ref{...}$}` from amsmath as in the first \ref above, will force things to the right size.
Any fix will amount to essentially doing the same as \text does internally but detecting when that is needed automatically, and doing it in away that don't break existing packages patching in to this area might mean a fix isn't available soon.
Thanks for the report, I'll leave this issue open unless or until a fix is added to the code. Hopefully the workaround with \text proves useful.
@davidcarlisle Thanks, David. I added an image, btw.
It's interesting to know that \mathrm
instead of \text
in your workaround doesn't produce the right small size. This implies that if you use references in the first argument of stackrel, include hyperref, and compile with latex, then you MUST include amsmath.
Perhaps, adapting stackrel to provide some information to hyperref might help. Though, I'm not into the internals to be of much help with any advice, I'm afraid.