# Referencing the section of an equation

I'm wondering if there's a way to reference the section that an equation is in.

\documentclass{article}
\begin{document}
\section{section 1}\label{sec:first}
$$\label{eq:eq1} 1+1=2 \\$$

\section{section2}\label{sec:second}
From equation \eqref{eq:eq1} in section \ref{sec:first}...
\end{document}


Basically, I'd like to replace \ref{sec:first} with a reference to the equation and get the section that it's in. Thank you in advance!

-

Probably you want to add the number of the section to the equation number.

In this way every reference to an equation contains also the section number and you don't have to add things like \ref{sec:first}.

\numberwithin{equation}{section}


MWE:

\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{section}

\begin{document}
\section{section 1}\label{sec:first}
$$\label{eq:eq1} 1+1=2 \\$$

\section{section2}\label{sec:second}
$$\label{eq:eq2} 2+2=4 \\$$

From equation \eqref{eq:eq1}...
\end{document}


Output:

-

If you want to have the section number of a reference, you have to use tricks, e.g. the zref package. There is already a solution to a similar question Extract Section number from Equation reference, however, so the merits should go to Werner ;-)

My version sets a special label using zref capabilities, however, you have to use \label{eq:eq1} and \localspeciallabel{eq:eq1} both, but I wrapped it into a common \commonlabel{eq:eq1} command.

The reference to the section is done with \eqsecref{eq:eq1} etc. I changed the name from \eqref, since there is already a command with that name in amsmath package.

\documentclass{article}
\usepackage{zref}

\makeatletter
\zref@newlist{specialreflist}
\zref@newprop{section}{\arabic{section}}
\newcommand*{\localspeciallabel}[1]{\zref@labelbylist{#1}{specialreflist}}%

\newcommand*{\eqsecref}[1]{%
% Do formatting of number here or outside
\zref@extractdefault{#1}{section}{??}
}%
\makeatother

\newcommand{\commonlabel}[1]{%
\label{#1}%
\localspeciallabel{#1}%
}%

\begin{document}

\section{section 1}\label{sec:first}

\section{section2}\label{sec:second}
$$\commonlabel{eq:eq1} 1+1=2 \\$$

\section{section 3}%\label{sec:three}

$$\commonlabel{eq:eq2} \sqrt{2} \approx 1.414 \\$$

From equation \ref{eq:eq1} in section \eqsecref{eq:eq1} it is clear that\ldots, whereas equation \ref{eq:eq2} in section \eqsecref{eq:eq2} shows that\ldots

\end{document}


-