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.

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!

share|improve this question
1  
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

3 Answers 3

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}
\hypersetup{colorlinks=true}

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

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

Result with red links

share|improve this answer

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}
\hypersetup{colorlinks=true}

    % 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} 
\begin{equation}\label{eq:pythagoras}
a^2+b^2=c^2\,.
\end{equation}
Looking at equation \ref{eq:pythagoras}, equation \eqref{eq:pythagoras}, or 
\autoref{eq:pythagoras}, \ldots
\end{document} 

enter image description here

share|improve this answer

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}
\begin{equation}
a = b \label{eqn}
\end{equation}
\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.

share|improve this answer
    
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

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.