# How to redefine \ref as \eqref?


-

If you really want to do this, in amsmath.sty, \eqref is defined as

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

so you could say

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\let\origref\ref
\renewcommand{\ref}[1]{\textup{\tagform@{\origref{#1}}}}
\makeatother

\begin{document}

\section{Test}\label{a}
Section~\ref{a}? Equation~\ref{b}
$$\label{b} a=b$$

\end{document}

Notice the inconsistencies that the redefinition introduces; you are cross-referencing section (1), but your document has section 1; a similar problem will appear for floats, and other objects in your document.

Perhaps, if you are interested in redefining the cross-reference format for a particular type of object, the cleveref package could be a better option; a little example in which I changed the formatting for cross-referencing figures, leaving all other cross.references unalatered:

\documentclass{article}
\usepackage{amsmath}
\usepackage{cleveref}

\crefformat{figure}{figure~(#2#1#3)}
\Crefformat{figure}{Figure~(#2#1#3)}

\begin{document}

\section{Test}\label{a}
Section~\ref{a}. Equation~\ref{b}. \Cref{c}? or \cref{c}?
$$\label{b} a=b$$
\begin{figure}
\centering
A
\caption{test figure}
\label{c}
\end{figure}

\end{document}

-
I take your point. I wanted to prevent from having references to equations in both forms (1) and 1 . I think it's better to use \eqref for references now. – Honza Zubáč Jul 14 '13 at 0:58

The macro \p@equation can be used to change the equation references of \ref. Usually \p@<counter> is used to add a prefix to the reference of counter <counter> and does not take an argument. But with an additional \expandafter, the counter value can be catched as simple argument:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand*{\p@equation}{%
\expandafter\@p@equation
}
\newcommand*{\@p@equation}[1]{%
\textup{\tagform@{#1}}% see definition of \eqref
}
\makeatother

\begin{document}
\section{Hello}\label{sec:hello}
$$\label{eq:einstein} E=mc^2$$
References: Section \ref{sec:hello} and equation \ref{eq:einstein}.
\end{document}

Drawback: The reference \ref should not be used inside \tag, otherwise the result is duplicated parentheses.

-

You can selectively define the format of \ref using the fncylab package, which is equivalent to (but more packaged than) Heiko's answer. For example:

\usepackage{fncylab}
\labelformat{equation}{(#1)}
\section{A section}\label{s:section}
$\label{eq:eqn} ...$
\ref{s:section}\ref{eq:eqn}

will print the equation number in parentheses but the section number normally. I have a standing preamble to define \labelformat{section}{Section~#1} and so on.

-