[Tex/LaTex] Do not count appendix with total page count

page-numberingpdf

When you open a PDF file made by TeX, you usually have some means of telling what the total page count is in the client GUI. I want to modify this page count such that the appendices is not counted along with the rest of the pages.

Best Answer

You can only control, the page contents and show the number of pages there:

Example with zref-abspage:

\documentclass{book}
\usepackage{zref-abspage}

\makeatletter
\AtBeginDocument{%
  \newcommand*{\mainpages}{}%
  \edef\mainpages{%
    \zref@ifrefundefined{afterlastmain}{??}{%
      \the\numexpr\zref@extractdefault{afterlastmain}{abspage}{1}-1\relax
    }%
  }%
  \zref@refused{afterlastmain}%
}
\usepackage{etoolbox}
\pretocmd\appendix{%
  \clearpage % or \cleardoublepage depending on counting an empty page
    % before the appendix
  \zref@labelbyprops{afterlastmain}{abspage}%
}{}{}
\makeatother

\begin{document}
This document has \mainpages{} pages without appendix pages.
\tableofcontents
\chapter{Introduction}
\chapter{Foobar}
\appendix
\chapter{First appendix}
\end{document}

Result

Change \clearpage to \cleardoublepage if the empty page before the appendix should also be included into the count.

Do you mean with GUI the PDF viewer that might show the number of pages, e.g. the advanced document properties of AR:

Advanced document properties

then you get the absolute number of pages. Anything else would be a bug in the PDF viewer.

Related Question