Simply use:
\newtheorem{test}{Theorem}
\renewcommand\thetest{\Roman{test}}
Defining a new theorem environment test
defines a new counter test
. The optional argument, such as you used, says the ‘test’ environment shares the counter of another theorem-like environment.
Your MWE produces 23 pages: title page (1) Executive Summary (3), ToC (1), chapters (15) and Appendix (5).
The title page and appendix should be excluded from the page count, giving a net count of 19 pages.
Using the pageslts
package it is possible to get a reference of the last page regardless of the numbering style. For example \lastpageref{LastPages}
will output the physical page number of the last page (23, but numbered 18).
The label lastpagetocount
was added to mark the last page to count.
To convert the LastPages
and the other page references to numbers, it was used the \getpagerefnumber
command provided by the refcount
package.
For convenience, the netpages
counter contains the result of the net number of pages to count, and the \NetPages
command will insert that number into the footnote.
The net number of pages to count is given by
\getpagerefnumber{LastPages} -\getpagerefnumber{LastPage} +\getpagerefnumber{lastpagetocount} -1
\documentclass[oneside]{book}
\usepackage{lipsum} % For dummy text
\usepackage{hyperref}
\usepackage{refcount} % convert pages references to numbers \getpagerefnumber <<<<<<
\usepackage{pageslts} % reference to the last physical pages <<<<<<
\newcounter{netpages} % store net number of pages to count <<<<<<
\newcommand{\NetPages}{% % added <<<<<<
\setcounter{netpages}{\the\numexpr\getpagerefnumber{LastPages} -\getpagerefnumber{LastPage} +\getpagerefnumber{lastpagetocount} -1\relax}
\thenetpages}
\begin{document}
\frontmatter
\begin{titlepage} Title
\end{titlepage}
% ------------------------ Included in page count
\chapter{Executive Summary}
Text \footnote{The total page numbers including the executive summary and chapters is \NetPages~pages}. \lipsum[1-10].
% ------------------------ ^^ Included in page count
\tableofcontents
\newpage
\mainmatter
% ------------------------ Included in page count
\chapter{First}
\lipsum[1-10]
\chapter{Second}
\lipsum[1-10]
\chapter{Third}
\lipsum[1-10]
\chapter{Fourth}
\lipsum[1-10]
\chapter{Fifth}
\lipsum[1-10]
\label{lastpagetocount} % added <<<<<<<<<<<<<<<<<<<<<<
% ------------------------ ^^ Included in page count%
\appendix
\chapter{Text}
\lipsum[1-10]
\end{document}
There was only supposed to be one page before the executive summary. Hence the -1 in the formula. If you have more pages present, change that number accordingly.
UPDATE This solution uses only the package zref
. It will count the pages between \zlabel{firstpagetocount}
and \zlabel{lastpagetocount}
, so it doesn't matter how many pages there are before or after that marks.
\documentclass[oneside]{book}
\usepackage[abspage,user,lastpage]{zref} % added <<<<<<<<<
\usepackage{lipsum} % For dummy text
\usepackage{hyperref}
\newcounter{netpages} % store net number of pages to count <<<<<<
\makeatletter
\newcommand{\calculatepages}{%
\setcounter{netpages}{\numexpr\zref@extract{lastpagetocount}{abspage} -\zref@extract{firstpagetocount}{abspage}+1\relax}
\thenetpages\
}
\makeatother
\begin{document}
\frontmatter
\begin{titlepage} Title
\end{titlepage}
% ------------------------ Included in page count
\chapter{Executive Summary}
\zlabel{firstpagetocount} % mark first page to count <<<<<<<<<<<<<<<<<
Text \footnote{The total page numbers including the executive summary and chapters is \calculatepages pages}. \lipsum[1-10].
% ------------------------ ^^ Included in page count
\tableofcontents
\newpage
\mainmatter
% ------------------------ Included in page count
\chapter{First}
\lipsum[1-10]
\chapter{Second}
\lipsum[1-10]
\chapter{Third}
\lipsum[1-10]
\chapter{Fourth}
\lipsum[1-10]
\chapter{Fifth}
\lipsum[1-10]
\zlabel{lastpagetocount} % % mark last page to count <<<<<<<<<<<<<<<<<
% ------------------------ ^^ Included in page count%
\appendix
\chapter{Text}
\lipsum[1-10]
\end{document}
Best Answer
This answer really answers the specific question of why the error occurs and how to fix it. It doesn't address the issues answered in the linked question. See egreg's answer for that kind of solution or use the solution here as part of the solution given in the linked question.
The
\Roman
command (and similar commands) expect a counter as an argument, not a number, but your\numexpr
yields a number, hence the error you receive:So if you want to do this simply by using the same method, you need to use the internal command
\@Roman
which expects a number.If you don't want to use the low level command
\@Roman
you can load thecalc
package, and use a temporary counter to achieve the same effect: