# Is there a possibility to make the \ref command return \part numbers in addition to chapter, section and subsection numbering?

As a default documentclass book numbers chapters consecutively regardless of the division into parts, and I suppose the \ref command had been designed with this in mind, returning as it does chapter, section and subsection numbering. The clause \@addtoreset{chapter}{part} will cause chapters to be numbered starting with 1 for each part. Is there a way of paramatrizing \ref to return part numbers?

\documentclass{book}
% RN. 10 Nov 2018
%=======================
%\usepackage{hyperref}
\makeatletter
\makeatother
\begin{document}
\chapter*{Preface}
Referencing both sections produce identical numbering. It would be helpful to distinguish parts:\\
\ref{A1}, page \pageref{A1}\\
\ref{B1}, page \pageref{B1}\\
\part{FIRST}
\chapter{A}
\section{A1}\label{A1}
\part{SECOND}
\chapter{B}
\section{B1}\label{B1}
\end{document}

• Something like \renewcommand*{\p@section}{\thepart.} (within \makeatletter...\makeatother)? – moewe Nov 10 '18 at 7:33
• Works like a charm. How do I mark this as the answer? – Reinhard Neuwirth Nov 10 '18 at 9:01
• You need to ping @moewe and ask that the text be re-posted as an answer, you can't mark comments as accepted answers. – David Carlisle Nov 10 '18 at 9:07

You can redefine \p@<counter> to modify the output of \ref without changing the actual representation of <counter> elsewhere. You might try something like \renewcommand*{\p@section}{\thepart.} or similar.

\documentclass{book}

\makeatletter
\renewcommand*{\p@chapter}{\thepart.}
\renewcommand*{\p@section}{\thepart.}
\renewcommand*{\p@subsection}{\thepart.}
\makeatother

\begin{document}
\chapter*{Preface}
Referencing both sections produce identical numbering. It would be helpful to distinguish parts:

\ref{A1}, page \pageref{A1}

\ref{B1}, page \pageref{B1}

\part{FIRST}
\chapter{A}
\section{A1}\label{A1}

\part{SECOND}
\chapter{B}
\section{B1}\label{B1}
\end{document}
`