Here is a possible approach, you will need two compilations to get the correct results.
\documentclass{book}
\usepackage{titlesec}
\titleformat{\part}[display]
{\centering\huge}
{\partname~\thepart}
{0pt}
{}
[\Large \chpterrange]
\makeatletter
\newcommand*\savechapnum[2]{
\@newl@bel{chapranges}{part-#2:first-chap}{\the\numexpr#1+1\relax}
\@newl@bel{chapranges}{part-\the\numexpr#2-1:last-chap}{#1}
}
\newcommand*\savelastchapnum[2]{
\@newl@bel{chapranges}{part-#2:last-chap}{#1}
}
\AddToHook{cmd/part/before}{%
\write\@auxout{%
\protect\savechapnum{\the\c@chapter}{\the\c@part}
}
}
\AddToHook{enddocument}{%
\write\@auxout{%
\protect\savelastchapnum{\the\c@chapter}{\the\c@part}
}
}
\newcommand*\chpterrange{%
\csname chapranges@part-\the\c@part:first-chap\endcsname
--%
\csname chapranges@part-\the\c@part:last-chap\endcsname
}
\makeatother
\begin{document}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\end{document}
Edit
With the following code you can change the format of the chapter range. The macro \chaprangeformat
accepts three arguments. The first is the format when there are no chapters in the current part, the second is the format when there is only one chapter, inside the second argument #1
represent this chapter number, and the third is the format otherwise, with #1
representing the first chapter inside the part, and #2
the last.
Here are two examples:
\documentclass{book}
\usepackage{titlesec}
\titleformat{\part}[display]
{\centering\huge}
{\partname~\thepart}
{0pt}
{}
[\Large \chpterrange]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand*\save@chapnum[2]{
\@newl@bel{chapranges}{part-\the\numexpr#2-1:last-chap}{#1}
}
\newcommand*\save@last@chapnum[2]{
\@newl@bel{chapranges}{part-#2:last-chap}{#1}
}
\AddToHook{cmd/part/before}{%
\write\@auxout{%
\protect\save@chapnum{\the\c@chapter}{\the\c@part}
}
}
\AddToHook{enddocument}{%
\write\@auxout{%
\protect\save@last@chapnum{\the\c@chapter}{\the\c@part}
}
}
\newcommand\chaprangeformat[3]{
\def\chap@range@format@a{#1}
\def\chap@range@format@b##1{#2}
\def\chap@range@format@c##1##2{#3}
}
\chaprangeformat{}{#1}{#1--#2} % default format
\newcommand*\chpterrange{%
\ifnum\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname=
\csname chapranges@part-\the\c@part:last-chap\endcsname\relax
\chap@range@format@a
\else
\ifnum\numexpr\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname+1=
\csname chapranges@part-\the\c@part:last-chap\endcsname\relax
\chap@range@format@b{\csname chapranges@part-\the\c@part:last-chap\endcsname}%
\else
\chap@range@format@c{\the\numexpr1+\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname\relax}%
{\csname chapranges@part-\the\c@part:last-chap\endcsname}%
\fi
\fi
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\part{Introduction}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
some text
\end{document}
\documentclass{book}
\usepackage{titlesec}
\titleformat{\part}[display]
{\centering\huge}
{\partname~\thepart}
{0pt}
{}
[\Large \chpterrange]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand*\save@chapnum[2]{
\@newl@bel{chapranges}{part-\the\numexpr#2-1:last-chap}{#1}
}
\newcommand*\save@last@chapnum[2]{
\@newl@bel{chapranges}{part-#2:last-chap}{#1}
}
\AddToHook{cmd/part/before}{%
\write\@auxout{%
\protect\save@chapnum{\the\c@chapter}{\the\c@part}
}
}
\AddToHook{enddocument}{%
\write\@auxout{%
\protect\save@last@chapnum{\the\c@chapter}{\the\c@part}
}
}
\newcommand\chaprangeformat[3]{
\def\chap@range@format@a{#1}
\def\chap@range@format@b##1{#2}
\def\chap@range@format@c##1##2{#3}
}
\chaprangeformat{}{#1}{#1--#2} % default format
\newcommand*\chpterrange{%
\ifnum\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname=
\csname chapranges@part-\the\c@part:last-chap\endcsname\relax
\chap@range@format@a
\else
\ifnum\numexpr\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname+1=
\csname chapranges@part-\the\c@part:last-chap\endcsname\relax
\chap@range@format@b{\csname chapranges@part-\the\c@part:last-chap\endcsname}%
\else
\chap@range@format@c{\the\numexpr1+\csname chapranges@part-\the\numexpr\c@part-1\relax:last-chap\endcsname\relax}%
{\csname chapranges@part-\the\c@part:last-chap\endcsname}%
\fi
\fi
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\chaprangeformat{No Chapters}{Only Chapter \@Alph{#1}}{Chapters \@Alph{#1}--\@Alph{#2}} % changing the format
\makeatother
\begin{document}
\part{Introduction}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
\chapter{Algebra}
\section{sec one} \subsection{subsec one} \subsection{subsec two} \section{sec two}
\chapter{Geometry}
\section{sec one} \section{sec two} \subsection{subsec one} \subsection{subsec two}
\part{Introduction}
some text
\end{document}
xcntperchap
package to count the number of chapters per part (I don't think it works with current texlive23).