Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing an article for a journal with AMS math equation style, e.g. "Eq. (1)". I want to hyperref the entire "Eq. (1)" and not merely the "1". Currently I use \renewcommand{\equationautorefname}{Eq.}. But this yields an hyperref'ed "Eq. 1". I prefer a solution in which I can continue using \autoref.

A solution is presented at How to use the command \autoref to implement the same effect when use the command \eqref?, but it uses \def and the journal style prohibits the use of Tex's low-level commands like \def, \edef, and \gdef.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

If you're not willing -- or allowed! -- to modify some lower-level TeX macros, you could still achieve your objective of getting parentheses placed automatically around cross-referenced equation numbers by (a) executing the following instruction in the preamble:

\usepackage[nameinlink,capitalize]{cleveref}

and (b) using \cref instead of \autoref to generate cross-references.

enter image description here

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink,capitalize]{cleveref}
\setlength\textwidth{3in} %% just for this example
\begin{document}
\begin{equation}\label{eq:pythag}
a^2+b^2=c^2
\end{equation}
A cross-reference to \cref{eq:pythag} via \verb+\cref+.
\end{document}

For more on various cross-referencing packages and, in particular, the capabilities of hyperref and cleveref in this regard, see the posting Cross-reference packages: which to use, which conflict?


Addendum: If you must use \autoref and want parentheses placed around the cross-referenced equation numbers, it's necessary to redefine the macro \theequation. Assuming you also use the amsmath package, it's also necessary to modify the auxilliary macro \tagform@. The following MWE shows how this may be done. (The directives \makeatletter and \makeatother are needed because some of the code involves the "special" character @.)

A side remark: If the journal's guidelines prohibit the use of \def in your document, using \renewcommand is probably frowned upon as well. If that's the case, you should probably use \cref instead of \autoref to create cross-references to equations...

enter image description here

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\let\oldtheequation\theequation
\renewcommand\tagform@[1]{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}}
\renewcommand\theequation{(\oldtheequation)}
\makeatother

\usepackage[colorlinks]{hyperref}
\renewcommand{\equationautorefname}{Eq.}

\usepackage[nameinlink,capitalize]{cleveref}
%% Need to undo the effect of redefinition of "\theequation" to use \cref:
\creflabelformat{equation}{#2\textup{#1}#3}  % No more parentheses around "#1"

\setlength\textwidth{3in} %% just for this example
\begin{document}
\begin{equation}\label{eq:pythag}
a^2+b^2=c^2
\end{equation}

A cross-reference to \autoref{eq:pythag} via \verb+\autoref+.

A cross-reference to Eq.~\eqref{eq:pythag} via \verb+\eqref+.

A cross-reference to \cref{eq:pythag} via \verb+\cref+.
\end{document}
share|improve this answer
    
I was under the supposition that hyperref and cleveref cannot be combined, but I was wrong. Thanks. Although my somewhat outdated Tex distribution does not support the nameinlink, I think your \cref solution is best. Fortunately I have to submit the tex-files and not the pdf. As for your side-remark, their style guide mentions \renewcommand and alikes may be used but not the low-level Tex commands. –  Bart Jul 15 at 10:21
    
@Bart - Glad you liked my solution. :-) Real quick: How old is your TeX distribution and cleveref package that the option nameinlink isn't recognized? I'm pretty sure the option has been around for at least two years, and probably longer. If it's at all feasible to do so, you may want to look into updating your TeX distribution. –  Mico Jul 15 at 11:05
    
It's from November 2011. So yes, I have to update (although I have been saying this too myself way too often...) –  Bart Jul 15 at 11:23

The following example defines \myeqref, which prepends the equation reference by Eq.~ and includes the prefix and the parentheses into the link. The prefix can be overwritten by the first optional argument.

The \autoref name macros do not have access to the counter, thus the following definition of \equationautorefname is just a dirty hack.

\documentclass[a5paper]{article}
\usepackage{amsmath}
\usepackage{hyperref}
\newcommand*{\myeqref}[2][Eq.~]{%
  \hyperref[{#2}]{#1(\ref*{#2})}%
}
\def\equationautorefname#1#2\null{%
  Eq.#1(#2\null)%
}

\begin{document}
\begin{equation}
\label{eq:einstein}
E=mc^2
\end{equation}
References: \myeqref{eq:einstein} and \myeqref[equation~]{eq:einstein}.\\
Reference: \autoref{eq:einstein}.
\end{document}

Result

share|improve this answer
    
It works, but can you somehow edit your solution in such a way that I can continue to use autoref for my equations? –  Bart Jul 14 at 15:02
    
I see the problem with autoref. Pity it cannot be done with \renewcommand, although thanks for sharing your solution. If it weren't for Mico's \cref solution I would have used your \myeqref. –  Bart Jul 15 at 10:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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