\llabel and \lref
Local labels
The following code defines two commands, \llabel and
\lref.
\llabel, when used inside an
athm or
aproof environment creates a label that is local to this theorem/proof and which
can be referenced inside the
athm or corresponding
aproof environment using \lref. This way, the same labels can be used
in different
athm/aproof
pairs.
\newcommand{\llabel}[1]{\label{\loc.#1}}
\ExplSyntaxOn
\clist_new:N \l_localreflist
\clist_new:N \l_reflist
\NewDocumentCommand{\lref} { m } {
\clist_set:No \l_localreflist {#1}
\clist_clear:N \l_reflist
\clist_map_inline:Nn \l_localreflist { \clist_put_right:Nn \l_reflist {\loc.##1} }
\cref{\l_reflist}
}
\NewDocumentCommand{\Lref} { m } {
\clist_set:No \l_localreflist {#1}
\clist_clear:N \l_reflist
\clist_map_inline:Nn \l_localreflist { \clist_put_right:Nn \l_reflist {\loc.##1} }
\Cref{\l_reflist}
}
\NewDocumentCommand{\itref}{ m m }{
\clist_set:No \l_localreflist {#2}
\clist_clear:N \l_reflist
\clist_map_inline:Nn \l_localreflist { \clist_put_right:Nn \l_reflist {#1.##1} }
\cref{\l_reflist}~in~\cref{#1}
}
\NewDocumentCommand{\Itref}{ m m }{
\clist_set:No \l_localreflist {#2}
\clist_clear:N \l_reflist
\clist_map_inline:Nn \l_localreflist { \clist_put_right:Nn \l_reflist {#1.##1} }
\Cref{\l_reflist}~in~\cref{#1}
}
\ExplSyntaxOffLike the \cref command,
\lref can take a comma separated list of labels
and there is also an \Lref version, analogous to
\Cref, for use at the start of a sentence.
Internally, the \llabel command creates a label of the form
[label of the current theorem environment].[local label].
The label can be referenced outside of the
athm/aproof pair by using this full form.
Here is an example that illustrates how these commands work:
\begin{athm}{lemma}{lem:sumrule}
Let $f,g\in C^1(\R,\R)$. Then
\begin{enumerate}[(i)]
\item \llabel{it:C1}
it holds that $f+g\in C^1(\R,\R)$,
\item \llabel{it:sumderivative}
it holds for all $x\in\R$ that
\begin{equation}
(f+g)'(x) = f'(x) + g'(x),
\end{equation}
and
\item \llabel{it:diffderivative}
it holds for all $x\in\R$ that
\begin{equation}
(f-g)'(x) = f'(x) - g'(x).
\end{equation}
\end{enumerate}
\end{athm}
\begin{aproof}
...
This \proves[ep] \lref{it:C1}.
...
This \proves[ep] \lref{it:derivative,it:diffderivative}.
\end{aproof}
\begin{athm}{thm}{thm:main}
Let $f\colon\R\to\R$ satisfy for all $x\in\R$ that $f(x) = \sin(x) + x^2$.
Then
\begin{enumerate}[(i)]
\item \llabel{it:C1}
it holds that $f\in C^1(\R,\R)$ and
\item \llabel{it:derivative}
it holds for all $x\in\R$ that
\begin{equation}
f'(x) = \cos(x) + 2x.
\end{equation}
\end{enumerate}
\end{athm}
\begin{aproof}
\Nobs that
\cref{lem:sumrule.it:C1,lem:sumrule.it:sumderivative} in \cref{lem:sumrule}
\prove
\lref{it:C1,it:derivative}.
\end{aproof}There is also a special command, \itref/\Itref, for expressions of the form
item (i) in Lemma 2. It takes two arguments, the label of the theorem and the local
label. In the above example, we could have used
\itref{lem:sumrule}{it:C1,it:sumderivative}
to output items (i) and (ii) in Lemma 1.