What exactly do you mean by "assign labels to numbered equations corresponding to their number in the text" ?
What exactly are you trying to achieve? What is the purpose of this in practice?
Let's use some vocabulary out of the area of database management and relational algebra:
Take all the referencing labels for a database for referencing whatsoever items of numbered sectioning within the document:
Each referencing label forms an entire data record belonging to that database.
(With this understanding of the term "referencing label" your question could be rephrased as:
Can we automatically assign entire data records belonging to the database of referenceable items of numbered sectioning to numbered equations corresponding to their number in the text?
That's why in the beginning of this answer I asked what exactly you mean.)
The single records are stored within the .aux-files in terms of these nice \newlabel
-entries.
The name of such a referencing label, which you introduce by the command
\label{⟨name of referencing label⟩}
,
forms the value of the data field "primary key" of the data record formed by the referencing label in question.
LaTeX will fill in for you the values of all other data fields belonging to that data record (page number, number of item of sectioning, name of anchor for hyperlinking, ...) automatically.
One thing you should never do in whatsoever kind of database management is changing values of primary keys of data records.
You are asking for a mechanism by means of which LaTeX shall do exactly this automatically.
Usually the set of data fields available in data records for \label
-\...ref
-referencing is hardcoded in LaTeX:
- The name of the referencing label. This is the primary key. You provide that name/the value of this data field via
\label{⟨name of referencing label⟩}
.
- Page number where the item of sectioning in question occurs. LaTeX will provide the value of this data field automatically. This data field is used by the
\pageref
-command.
- Formatted output of the value of the counter by means of which the item of sectioning in question is numbered. LaTeX will provide the value of this data field automatically. This data field is used by the
\ref
-command.
- In case of also using hyperref: Title of the item of sectioning in question. LaTeX will provide the value of this data field automatically. This data field is used by the
\nameref
-command.
- In case of also using hyperref: The name of the anchor for creating hyperlinks to the item of sectioning in question. LaTeX will provide the value of this data field automatically. This data field is used by all referencing-commands that also create hyperlinks. With the
\autoref
-command it is also used for concluding the correct contextual phrase.
- In case of also using hyperref: In case of importing referencing labels from other documents via the xr-package/the xr-hyper-package: URL of the external document which is to be hyperlinked. You provide the value of this data field as one of the arguments of the
\externaldocument
-command. This data field is used by all referencing-commands that also create hyperlinks.
Heiko Oberdiek's zref package provides means for adding and accessing and having LaTeX maintain automatically more data fields.
Be aware that (La)TeX is not intended to be a tool for modifying the tex-source-code of your document.
In other words: You don't use (La)TeX for producing the tex-source-code of your document/for working on the tex-source-code of your document.
You use (La)TeX in moments where you don't work on the tex-source-code of your document. In these moments you use (La)TeX in order to compile the tex-source-code as is for having (La)TeX produce a .dvi- or .pdf-output-file.
Thus automatic updating of names of referencing labels within arguments of referencing commands (e.g., \label
, \ref
, \pageref
, \nameref
, \autoref
, \hyperref
, and many more in case of using additional packages like refcount or cleveref or titleref or ...) is something that probably can take place while you work on the tex-source-code of your document and hereby use the tool/tex-input-editor of your choice.
(Even here it can be a difficult task because you can define referencing commands on your own and/or hide the names of referencing labels within macros. E.g., you can do:
\let\IveGotTheBluesOfWeirdness=\pageref
\newcommand\foo{\bar}%
\newcommand\bar{Eq3}%
...
\label{\foo}%
...
\ref{\bar} on page~\IveGotTheBluesOfWeirdness{Eq3}
...
)
Automatic updating of names of referencing labels while working on the tex-source-code of your document is something that cannot take place while (La)TeX is running.
Thus automatic updating of names of referencing labels is something that cannot be achieved during a (La)TeX-run by means of (La)TeX-macros.
This is something that probably can be achieved by means of the tool/tex-input-editor of your choice which you use while working on the tex-source-code of your document.
By the way:
When using the hyperref package, the macro \@currentHref
usually holds the name of the last hyperlink-anchor created so far.
That name in turn usually is created by means both of the name and the value of the counter and the values of all superordinate counters of the item of sectioning which a referencing label which is about to be created will refer to.
Thus when using the hyperref-package, you can probably patch the \label
-command so that it also adds an entry to a list of referencing labels wherin both the name of the label and name and numbering of the labeled item of sectioning do occur.
This list gives you a clue about which referencing label is related to which item of numbered sectioning.
This list might be useful when the stage of developing the tex-source-code of the document is (almost) over:
During the development of the tex-source-code of the document you can provide names for referencing labels that reflect the content or purpose of the item of sectioning that you are labeling.
If you really absolutely want this, you can, when developing is (almost) over, use this list for making more easy the task of replacing these names by names that reflect the number which the item of sectioning that you are labeling does have within the .dvi-/.pdf-output-file.
The following code comes without warranties of any kind. I, e.g., cannot guarantee that it will not break whatsoever package that also fiddles around with cross-referencing.
The following code is intended to provide an outline about how patching the \label
-command and maintaining a list of referencing labels could be implemented:
\documentclass{article}
\newcommand\mysavedcontentsline{}%
\let\mysavedcontentsline=\contentsline
\newcommand\mysavedaddcontentsline{}%
\let\mysavedaddcontentsline=\addcontentsline
\newcommand\mysavedlabel{}%
\usepackage{hyperref}
\makeatletter
\newcommand\addlabelnametolistofreferencinglabels[1]{%
\mysavedaddcontentsline{lrp}{referencinglabel}{%
Referencing~label \hyperref[#1]{\textbf{#1}} denotes \hyperref[#1]{\textbf{\@currentHref}}.%
}%
}%
\newcommand\l@referencinglabel[2]{#1\smallskip\\}%
\newcommand\listofreferencinglabels{%
%\begin{NoHyper}
\section*{List of referencing~labels}%
\begingroup
\let\contentsline=\mysavedcontentsline
\@starttoc{lrp}%
\endgroup
%\end{NoHyper}
}%
\AtBeginDocument{%
\let\mysavedlabel=\label
\renewcommand\label[1]{%
\@bsphack
\addlabelnametolistofreferencinglabels{#1}%
\mysavedlabel{#1}%
\@esphack
}%
}%
\makeatother
\begin{document}
\section{A section}\label{A section}
\subsection{A subsection}\label{subsectionlabel}
\subsection{Another subsection}\label{subsectionlabel2}
\begin{equation}
1+1=2\label{eq1+1=2}%
\end{equation}
\listofreferencinglabels
\end{document}
E.g., the anchor-name "equation.1.1" tells you that the referencing label "eq1+1=2" is about something where the equation-counter plays a rôle and where the equation-counter has a superordinate counter (the section-counter, by the way; in other words: In this document equations are numbered within \section
s and the equation-counter will be reset to 0 with the start of a new \section
) whose value was 1 and the equation-counter itself also had the value 1.
The refcheck-package might be of interest to you, too. It provides means for detecting referencing labels which are not referenced within the current document.
\label
mechanism. You do not need to know the number that will be used, nor change the label if the number changes. just use\label[fermat}
in the equation and then\ref{fermat}
will print whatever number is needed.