hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

Way too normal size of references in stackrel when running `latex`

Open ghost opened this issue 7 years ago • 2 comments

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.

output

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!

ghost avatar Sep 29 '17 22:09 ghost

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 avatar Sep 30 '17 08:09 davidcarlisle

@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.

ghost avatar Sep 30 '17 11:09 ghost