A proof of concept as you won't get warnings if the labels are wrong.
This style of references is very heavy and not a good service to your readers, in my opinion.
\documentclass{book}
\NewProperty{chapter}{now}{0}{\arabic{chapter}}
\NewProperty{section}{now}{0}{\arabic{section}}
\NewProperty{subsection}{now}{0}{\arabic{subsection}}
\NewDocumentCommand{\chapterlabel}{m}{%
\label{ch:#1}%
\RecordProperties{ch@:#1}{chapter}%
}
\NewDocumentCommand{\sectionlabel}{m}{%
\label{sec:#1}%
\RecordProperties{sec@:#1}{chapter,section}%
}
\NewDocumentCommand{\subsectionlabel}{m}{%
\label{subsec:#1}%
\RecordProperties{subsec@:#1}{chapter,section,subsection}%
}
\ExplSyntaxOn
\NewDocumentCommand{\chapref}{m}
{
\str_if_eq:eeTF { \property_ref:nn { ch@:#1 } { chapter } } { \arabic{chapter} }
{
this~chapter
}
{
chapter\nobreakspace\property_ref:nn { ch@:#1 } { chapter }
}
}
\NewDocumentCommand{\secref}{m}
{
\str_if_eq:eeTF { \property_ref:nn { sec@:#1 } { chapter } } { \arabic{chapter} }
{% we're in the same chapter
\str_if_eq:eeTF { \property_ref:nn { sec@:#1 } { section } } { \arabic{section} }
{% we're in the same section
this~section
}
{% different section, same chapter
section\nobreakspace\property_ref:nn { sec@:#1 } { section }
}
}
{% different chapter
section\nobreakspace\property_ref:nn { sec@:#1 } { section }~
of~chapter\nobreakspace\property_ref:nn { sec@:#1 } { chapter }
}
}
\NewDocumentCommand{\subsecref}{m}
{
\str_if_eq:eeTF { \property_ref:nn { subsec@:#1 } { chapter } } { \arabic{chapter} }
{% we're in the same chapter
\str_if_eq:eeTF { \property_ref:nn { subsec@:#1 } { section } } { \arabic{section} }
{% we're in the same section
\str_if_eq:eeTF { \property_ref:nn { subsec@:#1 } { subsection } } { \arabic{subsection} }
{% we're in the same subsection
this~subsection
}
{% different subsection, same section
subsection\nobreakspace\property_ref:nn { subsec@:#1 } { subsection }
}
}
{% different section, same chapter
subsection\nobreakspace\property_ref:nn { subsec@:#1 } { subsection }~
of~section\nobreakspace\property_ref:nn { subsec@:#1 } { section }
}
}
{% different chapter
subsection\nobreakspace\property_ref:nn { subsec@:#1 } { subsection }~
of~section\nobreakspace\property_ref:nn { subsec@:#1 } { section }~
of~chapter\nobreakspace\property_ref:nn { subsec@:#1 } { chapter }
}
}
\ExplSyntaxOff
\begin{document}
\chapter{Test}\chapterlabel{testchapter1}
\chapref{testchapter1} --- \chapref{testchapter2}
\section{Test}\sectionlabel{testsection1}
\subsection{Test}\subsectionlabel{testsubsection1}
\section{Second}\sectionlabel{testsection2}
A: \secref{testsection1}. B: \secref{testsection2}. C: \secref{testsection3}
\subsection{AAA}\subsectionlabel{testsubsection2}
A: \subsecref{testsubsection1}.
B: \subsecref{testsubsection2}.
C: \subsecref{testsubsection3}.
\chapter{Second}\chapterlabel{testchapter2}
\section{Again}\sectionlabel{testsection3}
\subsection{BBB}\subsectionlabel{testsubsection3}
\end{document}
We record more properties for a single \...label and so we're able to check them one by one.

variorefpackage. Somehow https://tex.stackexchange.com/q/33017/277964 could also be related. – cabohah Jan 26 '24 at 16:56zref-checkcan assist you with some of your requirements. (Though not all, and even in those in which it can, it offers just some support to keep consistency rather than proper automation). – gusbrs Jan 26 '24 at 23:17