# Mixed up roman and arabic page numbering in foot line using pageref

In my essay, all parts before the text part have to be numbered in Roman numbers. After the title page, the table of contents gets the correct number I. The following pages containing sections are numbered with 1,2,... The minimal example will show this:

\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{}
\fancyfoot[R]{
\footnotesize
page \thepage\space of \pageref{LastPage} \\
}

\begin{document}
\begin{titlepage}
This is the title.
\end{titlepage}
\pagenumbering{Roman}
\tableofcontents
\newpage
\pagenumbering{arabic}
\section{Section 1}
\subsection{Subsection 1.1}
\end{document}


However, the reference to the LastPage does not adapt to the defined \pagenumbering. As you will see, a line like this occurs:

page I of 1

My aim is to "split up" the LastPage reference in one for the "Roman" part at the beginning of the document and another one for the "arabic" part, for example:

page II of IV.....(and later on)......page 5 of 15

I already looked in the thread How can I add “page # of ##” on my document?, but I could not figure out an appropriate solution.

-
Do you have the option of restricting the "page x of y" page numbering system to the part of the document that starts with (arabic) 1? – Mico Apr 22 '13 at 20:09
@Mico: Maybe this could be an option concerning formatting guideline...however, I do not know to restrict fancy to a certain area of pages. Could you please provide an example? – PWillms Apr 22 '13 at 20:29

Here's a variant of an answer of mine

\documentclass{article}
\usepackage{refcount}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all fields
\fancyfoot[R]{%
\footnotesize
page \thepage\space of \computelastpage
}

\usepackage{lipsum}

\makeatletter
\newif\if@mainmatter
\newcommand{\frontmatter}{%
\clearpage
\pagenumbering{Roman}
\edef\computelastpage{%
\uppercase{\romannumeral\numexpr\getpagerefnumber{LastFrontPage}-1\relax}}}
\newcommand{\mainmatter}{%
\clearpage
\immediate\write\@auxout{\noexpand\newlabel{LastFrontPage}{{}{\arabic{page}}}}%
\@mainmattertrue
\pagenumbering{arabic}
\def\computelastpage{\pageref{LastPage}}}
\makeatother

\begin{document}
\begin{titlepage}
This is the title.
\end{titlepage}

\frontmatter
\tableofcontents

\newpage

\lipsum

\mainmatter
\section{Section 1}
\subsection{Subsection 1.1}
\lipsum
\end{document}


I added some Lipsum paragraphs just to show the result. You have also a tidier document, by hiding \pagenumbering instructions in a higher level instruction.

The \mainmatter instruction writes a \newlabel referring to the just created new page, but before changing numbering. So the page number will be one more than the front matter final page. With a suitable definition of \computelastpage (which is different in front and main matter) we can refer to the number. Using \getpagerefcount provided by refcount is crucial.

-