# Refer to some equation number in different environments

I hope there is a solution for this. When I refer to some equation I always get something like 37, but I would like to have (37). I could make a new command but the problem is I use many kind of environments in my text: equation (needs \eqref), multline (needs \ref), theorems (need \ref). I don't want parantheses when referring to theorem numbers. Any advice is appreciated.

• Would you be able to provide an example of the equations causing these problems? You usage of \label could be incorrect. – Werner Jan 13 '12 at 20:09
• Lockstep provided me a solution, thanks anyway. – Nadori Jan 13 '12 at 20:34

One could use the "extension of counter referencing" described in section 53.2 of source2e and then redefine \p@equation.

\documentclass{article}

\makeatletter
\renewcommand*\refstepcounter[1]{%
\stepcounter{#1}%
\protected@edef\@currentlabel
{\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
}
\renewcommand{\p@equation}[1]{(#1)}
\makeatother

\begin{document}

\section{foo}\label{foo}

$$\label{test} a^2 + b^2 = c^2$$

See equation~\ref{test} in section~\ref{foo}.

\end{document}


if you're using amsmath, just use \eqref{ <label> } which includes the parentheses and keeps the whole thing upright even in an italic (e.g. theorem) environment. it really doesn't matter what you're using it for; it should work with any label.

reading the question more carefully, you say you don't want parentheses when referring to thworems. then just use \ref -- but if you'd like them upright like \eqref, then use \textup{\ref{...}} when not in a "guaranteed" upright environment'