1

Using this code

\documentclass{article}
\usepackage[]{amsmath, amssymb, amsthm}
\usepackage{mathtools}
\usepackage{hyperref}

\renewcommand{\thesection}{\arabic{section}}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}

\begin{document}

\begin{proposition}\label{A}
  A
\end{proposition}

\begin{equation}
  E = mc^{2}    \label{B}
\end{equation}

\begin{align*} 
  a &\xLeftrightarrow{\ref{A}} b  \\
    &\xLeftrightarrow{\eqref{B}} c
\end{align*}

\end{document}

I get this Version 1

If I comment out \usepackage{hyperref}, I get this

Version 2

Finally, if I use the trick given as an answer to this question, namely

\makeatletter
\renewcommand*{\eqref}[1]{%
  \hyperref[{#1}]{\textup{\tagform@{\ref*{#1}}}}%
}
\makeatother

I get this Version 3

However, I would like to have the same size as in the second picture when I use hyperref. How to do it?

  • i can't reproduce this problem with pdflatex (tex live 2016). but instead of using \textup{...} you can use \text{\upshape...}} which (for me) reliably produces the smaller size embellishment. – barbara beeton Nov 9 '17 at 14:44
  • @barbara-beeton I am indeed using dvips followed by ps2pdf because I am using the package GasTeX. I tried to use your suggestion, but unfortunately it gives me the third version (the larger size). – J.-E. Pin Nov 9 '17 at 14:54
  • @barbarabeeton: Yes, it’s a known issue with the hdvips driver for hyperref. – GuM Nov 9 '17 at 19:06
2

instead of using \textup, use the combination \text{\upshape ...}.

in a comment, you said that your output is dvi, which is then converted to pdf.

this example was produced with dvi output, converted to pdf with acrobat, not the ps2pdf route you took. however, i've reproduced the experiment with dvips + ps2pdf and achieved the same result. both refs are linked, although this isn't visible in the output as shown.

\documentclass{article}
\usepackage[]{amsmath, amssymb, amsthm}
\usepackage{mathtools}
\usepackage{hyperref}

\renewcommand{\thesection}{\arabic{section}}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}

\begin{document}

\begin{proposition}\label{A}
  A
\end{proposition}

\begin{equation}
  E = mc^{2}    \label{B}
\end{equation}

\begin{align*} 
  a &\xLeftrightarrow{\ref{A}} b  \\
    &\xLeftrightarrow{\eqref{B}} c
\end{align*}

\begin{align*} 
  a &\xLeftrightarrow{\text{\upshape\ref{A}}} b  \\
    &\xLeftrightarrow{\text{\upshape\eqref{B}}} c
\end{align*}

\end{document}

output of example code

as GuM points out in a comment, using \textup is equivalent to \text{\upshape} when amsmath or even just amstext is used.

  • When the amsmath package is loaded, \textup{...} is equivalent to \text{\upshape ...}, that is, it uses \mathchoice (through the \nfss@text macro), so you could as well say \xLeftrightarrow{\textup{\ref{A}}} and \xLeftrightarrow{\textup{\eqref{B}}} (actually, the amstext package suffices for this). – GuM Nov 9 '17 at 19:04
2

I still find @barbarabeeton’s answer a bit confusing: first, it claims that the key to the solution is to use \text{\upshape ...} instead of \textup{...}, then, in the final paragraph, it remarks that \text{\upshape ...} is equivalent to \textup{...} when the amsmath package is loaded. I hope, therefore, that I won’t be reproached if I add this new answer for the sake of clarity.


The problem

To begin with, let us briefly describe the source of the problem. As Loop Space explained some years ago in their excellent answer to How do I get references in subscripts to be the right size when compiling to dvi with hyperref?, this is a known issue of the hdvips driver, which is the driver the hyperref package normally uses when DVI output is asked for. Basically, this driver typesets the link in a box, using an \hbox command, and this causes TeX to typeset it in the “current font for text”, which normally is the font that was current just before the math formula began, irrespective of the “current math style” (that is, text style vs. script style vs. scriptscript style). This explains why, in the case of

\xLeftrightarrow{\ref{A}}

the reference is set at 10 points, instead of at 7 points, as it would be appropriate for a superscript. To understand why this is not the case when \eqref is used, we have first to discuss how the use of \text (or \textup) affects the result of the above.


The solution with \text (and siblings)

The amstext package (which is automatically incorporated by amsmath) defines the handy command \text, which, roughly speaking, typesets its argument in a context where the “current font for text” has been redefined in order to adjust its size to the “current math style” (this is an over-simplification of what actually happens, and TeX experts will undoubtedly frown at it); this means, in particular, that a smaller size will be used when \text{...} appears in a superscript or subscript.

Note that \text{..} adjusts only the size of the “current font for text”, leaving all other attributes (e.g., weight, shape) unchanged. However, the amstext package is given permission by the LaTeX kernel to “hook into” the kernel-defined commands for typesetting a piece of text in a certain shape or weight or family, like \textit, \textup, \textbf, \texttt, etc., in order to endow them with the ability, when they are used in math mode, to adjust as well the size of the font to the “current math style”, exactly in the same way as \text does. This means that, for example, \textup{...} will produce, when used in math mode, exactly the same output as \text{\upshape ...}.

I’ve stressed the condition “when used in math mode”, because that is the key to the solution, not the fact that \text{\upshape ...} is used instead of \textup{...}: you can use either construction (since, I repeat, they are equivalent to each other), but in order to have it yield the desired size-adjusting effect, you have to issue it while still in math mode; if you issue it “inside” the text generated by \ref, it will occur inside the box into which the hdvips driver puts that text, that is, already in text mode; and the “blessing” operated on them by the amstext package is—obviously!—not effective when the commands of the \text?? family are used in text mode.

Let's now see that this indeed explains the output the OP is getting in all the situations mentioned in the question.

Why amsmath’s \eqref works nicely

The amsmath package defines the \eqref command as follows:

\newcommand{\eqref}[1]{\textup{\tagform@{\ref{#1}}}}

This means that

\xLeftrightarrow{\eqref{B}}

is expanded to

\xLeftrightarrow{\textup{\tagform@{\ref{B}}}}

Now, the hdvips driver puts the reference generated by \ref{B} into an \hbox, but what matters is that the \textup command occurs in math mode, and therefore adjusts the size of the current font to the current math style, which is script style; the ensuing \hbox command will pick up this updated current font, so the size will be appropriate for a subscript.

Why the redefined \eqref does not work nicely

Let’s now see what happens when one redefines the \eqref command as follows:

\makeatletter
\renewcommand*{\eqref}[1]{%
  \hyperref[{#1}]{\textup{\tagform@{\ref*{#1}}}}%
}
\makeatother

In this case,

\xLeftrightarrow{\eqref{B}}

becomes

\xLeftrightarrow{\hyperref[{B}]{\textup{\tagform@{\ref*{B}}}}}

We see that now it is the \hyperref command that gets executed in math mode: this command makes the text generated by its mandatory argument into a link to the position associated with the label specified in the optional argument. But we know that the hdvips driver uses an \hbox for the links, and hence it executes the mandatory argument \textup{\tagform@{\ref*{B}}} inside this \hbox to obtain the text that makes up the link in question: this means that the \textup command is executed in text mode, where it does not adjust the font size (recall that \ref*{B}, with the *, typesets a plain, i.e., non-active, reference to \label{B}). On the other hand, if you move \textup out of the \hyperref command, that is, if you say

\makeatletter
\renewcommand*{\eqref}[1]{%
  \textup{\hyperref[{#1}]{\tagform@{\ref*{#1}}}}%
}
\makeatother

you’ll see that the reference is typeset in a smaller size, as desired (while being made into an active link).


A sample program

We'll now illustrate with an example what we’ve been saying thus far.

Consider the following code

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools} % also loads amsmath
\usepackage{amsthm}
\usepackage{hyperref}

\makeatletter

\newcommand*{\myeqref}[1]{%
    \hyperref[{#1}]{\textup{\tagform@{\ref*{#1}}}}%
}

\makeatother

\newtheorem{proposition}{Proposition}[section]



\begin{document}

\begin{proposition}\label{A}
    A nifty claim.
\end{proposition}

\begin{proof}
    We start from Einstein's famous equation
    \begin{equation}
        E = mc^{2}
        \label{B}
    \end{equation}
    and deduce that blah blah blah\ldots
\end{proof}

Without \verb|\textup|:
\begin{align*} 
  a &\xLeftrightarrow{\ref{A}} b  \\
    &\xLeftrightarrow{\eqref{B}} c \\
    &\xLeftrightarrow{\myeqref{B}} d
\end{align*}

With \verb|\textup|:
\begin{align*} 
  a &\xLeftrightarrow{\textup{\ref{A}}} b  \\
    &\xLeftrightarrow{\textup{\eqref{B}}} c \\ % pointless
    &\xLeftrightarrow{\textup{\myeqref{B}}} d % inner "\textup" unneeded
\end{align*}

\end{document}

and the output it produces (via latex → dvips → ps2pdf):

Output of the above code

This code compares the output of three different constructs (\ref, \eqref, and the redefined version of \eqref proposed by the OP, here called \myeqref) used with and without a surrounding \textup in an otherwise identical context: you can see that with the outer \textup the output is always correct. However, the use of the outer \textup is superfluous (the comment says “pointless”) in the case of \eqref; on the other hand, in the case of \textup{\myeqref{B}} it is the inner \textup, that is, the one inside the definition of \myeqref, that is unneeded, as already remarked above. It should also be noted that, with \myeqref, the parentheses around the reference become part of the link.

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.