My understanding is that \@currentlabel holds a register value. This also applies when hyperref is used.
I was having a look at kpsewhich ltxref.dtx when I read that \@currentlabel handles situations when \label is put outside of an environment (this happens when you tack them onto headings e.g. \section{blah}\label{blah}).
Its definition is
\def\@currentlabel{}
This looks to me like effectively initializing a macro. I proceeded to review the document, source2e, but I still do not understand \@currentlabel.
To get a proper
\@currentlabelwe have to redefine it for the whole display. Note that we can't use\refstepcounteras this results in\@currentlabelgetting restored at the wrong and thus always writing the first label to the.auxfile.
What is meant by whole display?
If I create my own sectioning/heading command, is it then a requirement to include \refstepcounter{CNT} if I want to be able to tack on \label{} to it?
Does titlesec automatically add \refstepcounter{CNT} to new sectioning commands?
In the sectioning/heading definitions, there is \refstepcounter{CNT}. This is the only connection I found to \@currentlabel.
A referencable counter CNT is incremented by the command
\refstepcounter{CNT}, which sets\@currentlabel == {CNT}{eval(\p@cnt\theCNT)}. The command\label{FOO}then writes the following on file\@auxout : \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
\def\refstepcounter#1{\stepcounter{#1}%
\protected@edef\@currentlabel
{\csname p@#1\endcsname\csname the#1\endcsname}%
}
It seems like magic how \subsection{subsec1}\label{subsec1} results in \@currentlabel equal to 1.1:
\newlabel{subsec1}{{1.1}{1}{subsec1}{subsection.1.1}{}}
Example
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{sec1}
\label{sec1}
\subsection{subsec1}
\label{subsec1}
\subsubsection{subsubsec1}
\label{subsubsec1}
\paragraph{par1}
\label{par1}
\section{sec2}
\end{document}
Relevant .aux lines
\newlabel{sec1}{{1}{1}{}{section.1}{}}
\newlabel{subsec1}{{1.1}{1}{subsec1}{subsection.1.1}{}}
\newlabel{subsubsec1}{{1.1.1}{1}{subsubsec1}{subsubsection.1.1.1}{}}
\newlabel{par1}{{1.1.1.1}{1}{par1}{paragraph.1.1.1.1}{}}
hyperrefthat adds a level of complication that's irrelevant for understanding\@currentlabel. – egreg Jul 13 '17 at 13:04\newlabel: from 2 parameters > 5 parameters in the second{}– Jonathan Komar Jul 13 '17 at 13:09