Addition to egreg's answer:
\label
is redefined by package nameref
that is loaded by hyperref
via \AtBeginDocument
. Therefore it is enough to load nameref
before redefining:
\usepackage{hyperref}
\usepackage{nameref}
\newcommand{\origlabel}{}
\let\origlabel\label
\renewcommand*{\label}[1]{\origlabel{vol1:#1}}
But the redefinition can additionally be put into \AtBeginDocument
for the case there are other packages involved.
Also the questions talks about two labels, then additional stuff has to be done. \label
tries to be invisible regarding spaces. If space is detected before it suppresses the following spaces. This mechanism does not work for consecutive \label
s and the new definition should be surrounded by \@bsphack
and \@esphack
:
\makeatletter
\AtBeginDocument{%
\newcommand*{\orig@label}{}%
\let\orig@label\label
\renewcommand*{\label}[1]{%
\@bsphack
\orig@label{#1}%
\orig@label{vol1:#1}%
\@esphack
}%
\makeatother
}%
What is the purpose of the added vol1:
? If the labels are used inside another document,
then packages that are able to import foreign labels (xr
, xr-hyper
, zref-xr
) usually allow the addition of a prefix for the label names. Assuming the main TeX file is called firstvolume.tex
, then the other document uses something like:
xr/xr-hyper: \externaldocument[vol1:]{firstvolume}
zref-xr: \zxrsetup{...}\zexternaldocument*[vol1:]{firstvolumne}
\label{x}
, I get\newlabel{vol1:x}{{1}{1}}
in theaux
file.