# How to use the command \autoref to implement the same effect when use the command \eqref?

For example, the first equation of Section 1 in a tex file is numbered in the form (1.1), When we use the commands \autoref and \eqref for referring it, the compiled pdf file will show Equation 1.1 and (1.1), respectively.

Now the problem is that how can I just use the command \autoref to implement the same effect when use the command \eqref.

By the way, please do not use the package cleveref!

-
Would you please add a MWE? –  egreg Apr 18 '12 at 13:04
Although you should know best of course, let me raise the inescapable style question. "(1.1)" is a way of saying "Equation 1.1", so "Equation (1.1)" looks clearly wrong to me. –  Stephan Lehmke Apr 18 '12 at 15:52
@StephanLehmke: Would the following sentence meet with your approval? "As may be seen by the expressions given in equations 1 and 2, 3 out of 4 dentists recommend Brand-X tooth paste to their patients." To me, not placing parentheses around the first two numerals looks clearly wrong... –  Mico Apr 18 '12 at 19:36

Macro \autoref of package hyperref calls \<counter>autorefname followed by a unbreakable space ~ and the number. Finally \null is appended (some inheritance from LaTeX). This can be used to define \equationautorefname as macro that catches the equation number in a parameter.

\documentclass{article}
\usepackage{amsmath,hyperref}

\def\equationautorefname~#1\null{%
Equation~(#1)\null
}

\begin{document}
$$\label{eq:pythagoras} a^2+b^2=c^2\,.$$
As may be seen in equation \eqref{eq:pythagoras} or, alternatively,
in \autoref{eq:pythagoras}, \ldots
\end{document}


-

Rather than fiddle with the definition of \autoref, you can use the \tagform@ command (provided by the amsmath package) to insert parentheses automatically around cross-referenced equation numbers. This works regardless of the cross-referencing command (\ref, \autoref, etc) you employ. The following MWE shows how this may be done:

\documentclass{article}
\usepackage{amsmath,hyperref}

% First, save the current form of \theequation
\let\oldtheequation\theequation
\makeatletter
\def\tagform@#1{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}}
\renewcommand{\theequation}{(\oldtheequation)}
\makeatother

\begin{document}
$$\label{eq:pythagoras} a^2+b^2=c^2\,.$$
Looking at equation \ref{eq:pythagoras}, equation \eqref{eq:pythagoras}, or
\autoref{eq:pythagoras}, \ldots
\end{document}


-

I think that getting \autoref to put parentheses around equation numbers but not around section numbers, etc. would require a lot of hacking (I could be wrong though). However, you can create a new command \eqautoref, say, which can be used in place of \eqref.

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\numberwithin{equation}{section}
\makeatletter
\renewcommand\equationautorefname{\@gobble}
\makeatother
\newcommand\eqautoref[1]{(\autoref{#1})}
\begin{document}
\section{A section}
$$a = b \label{eqn}$$
\eqautoref{eqn}
\end{document}


The \@gobble macro eliminates the space that would normally go between whatever \equationautorefname expands to ('Equation' by default) and the equation number.

-
Will this new command preserve \autoref's "habit" of automatically inserting the appropriate label name (in this case, "Equation") before the number in question? –  Mico Apr 18 '12 at 15:10
@Mico --- No. I thought the OP wanted hyperlinked references that looked the same as the output of \eqref. –  Ian Thompson Apr 18 '12 at 15:18
Interesting -- I thought the OP's question was directed only at the automatic insertion of parentheses. You may be correct in your interpretation... –  Mico Apr 18 '12 at 15:20