This following approach based on the idea of label
defined by the LaTeX-Kernel. First you have to define a new kind of label which write the needed information to the aux
file.
Normally the command \label
writes the following in the aux file
\newlabel{#1}{{\@currentlabel}{\thepage}}
where \@currentlabel
is the current number (in your case the equation number).
Now you need a the current section number instead of the equation number so the information in the aux
file should be:
\newlabel{sec@#1}{{\thesection}{\thepage}}
The prefix sec@
is used to avoid multiple labels.
amsmath
uses his own definition of \label
named \label@in@display
. To make sure that you don't have to type two different labels the definition will expand by the new label command.
Now I have to define a new reference command which is able to handle the new label. The idea based on the definition of \ref
(see latex.ltx).
The explanation of the commands \@bsphack
a.s.o. can be found in the document macros2e.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand\sec@label[1]{%
\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{sec@#1}{{\thesection}{\thepage}}}%
\@esphack}
\def\label@in@display#1{%
\ifx\df@label\@empty\else
\@amsmath@err{Multiple \string\label's:
label '\df@label' will be lost}\@eha
\fi
\sec@label{#1}\gdef\df@label{#1}%
}
\def\secref#1{\expandafter\@setref\csname r@sec@#1\endcsname\@firstoftwo{#1}}
\def\secpageref#1{\expandafter\@setref\csname r@sec@#1\endcsname\@secondoftwo{#1}}
\makeatother
\begin{document}
\section{foo}
Text
\section{foo}
Text
\section{foo}
Text
\begin{equation}
a+b=c\label{eq1}
\end{equation}
\section{bar}
See equation in section \secref{eq1} on page \secpageref{eq1}
\end{document}

The same with hyperref
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\makeatletter
\newcommand\sec@label[1]{%
\@bsphack
\if@filesw
\begingroup
\edef\@currentlabstr{%
\expandafter\strip@prefix\meaning\@currentlabelname
}%
\protected@write\@auxout{}{%
\string\newlabel{seceq@#1}{%
{\@currentlabel}%
{\thepage}%
{\@currentlabstr}%
{\@currentHref}%
{\theHsection}%%%%%%%%<- Define the reference counter
}%
}%
\endgroup
\fi
\@esphack}
\def\label@in@display#1{%
\ifx\df@label\@empty\else
\@amsmath@err{Multiple \string\label's:
label '\df@label' will be lost}\@eha
\fi
\sec@label{#1}\gdef\df@label{#1}%
}
\newcommand*\@refsecstar{}
\newcommand*\T@secref{}
\long\def\@fifthoffive#1#2#3#4#5{#5}
\def\@refsecstar#1{%
\HyRef@StarSetRef{seceq@#1}\@fifthoffive
}
\def\T@secref#1{\hyperref[{#1}]{\secref*{#1}}}%
\DeclareRobustCommand\secref{%
\@ifstar\@refsecstar\T@secref
}%
\makeatother
\begin{document}
\section{foo}
Text
\section{foo}
Text
\section{foo bar}\label{sec}
Text
\begin{table}[!ht]
\caption{table cpation}
\label{tab}
\end{table}
\addtocounter{equation}{5}
\begin{equation}
a+b=c\label{eq1}
\end{equation}
\begin{align}
a+b=c\label{eq2}
\end{align}
\clearpage
\section{bar}
See equation in section \secref{eq1} on page \pageref{eq1}
See equation in section \secref*{eq1} on page \pageref*{eq1}
\end{document}
amsmath
it's sufficient to say\numberwithin{equation}{section}
.documentclass
are you using? If your document useschapters
then the default labelling should be(1.1)
,(1.2)
,(1.3)
, etc where1
is thechapter
number, and1
,2
,3
etc are the equation numbers. If you use @egreg's suggestion, the labels and cross references should change automagically, to1.1.1
,1.1.2
,1.1.3
report
document class. We are trying to avoid having the three-number references because we think it looks clunky. Right now the references show up as section.equation. The problem occurs where we currently have a \pageref, and the publisher has asked us to reference the section instead. That get's tedious, so we were looking for a fast change.