[Tex/LaTex] autoref and braces around equation number

equationshyperref

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.

Best Answer

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}