# How to get the physical (absolute) page number

I have an article of nine pages which include three kinds of page number styles – Roman, arabic and Alph. The layout of the pages and their logical numbers are: I II 1 2 3 4 A B C.

I want to get the physical (absolute) page number of a given page from a macro (or counter). For example, it should be 7 for the page with logical number A, and 5 for the page with logical number 3.

I tried with the LaTeX macro \ReadonlyShipoutCounter, but this macro did not give the right number.

Anyone can help me? Preferably without using other packages.

Example:

\documentclass{article}
\usepackage{geometry,fancyhdr}
\geometry{showframe}
\pagestyle{fancy}

% My Try: (not succeessful)

% My Intent:
\newcommand\abspage{...}%output the absolute page number of a certain page in article

\chead{Currrent Physical Page Number is: \abspagenumber}
%\lhead{Currrent Physical Page Number is: \abspage}
\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber
\clearpage
sencond page\par current absolute page number is: \abspagenumber
\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber
\clearpage
fourth page\par current absolute page number is: \abspagenumber
\clearpage
fifth page\par current absolute page number is: \abspagenumber
\clearpage
sixth page\par current absolute page number is: \abspagenumber
\clearpage
\pagenumbering{Alph}
seventh page\par current absolute page number is: \abspagenumber
\clearpage
eighth page\par current absolute page number is: \abspagenumber\par
\clearpage
nineth page\par current absolute page number is: \abspagenumber
\end{document}


### Edit:

Base on the solution given by Ulrike Fischer I have another request:
How can I make \abspagenumber work in a watermark?

\documentclass{article}
\usepackage{geometry,fancyhdr,eso-pic}
\geometry{showframe}
\pagestyle{fancy}

\chead{Currrent Physical Page Number is: \abspagenumber}

\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber

\clearpage
sencond page\par current absolute page number is: \abspagenumber

\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber

\clearpage
fourth page\par current absolute page number is: \abspagenumber

\clearpage
fifth page\par current absolute page number is: \abspagenumber
\clearpage
sixth page\par current absolute page number is: \abspagenumber
\end{document}

• If you load the hyperref packge, you can use the count \Hy@pagecounter (all counters are counts, but not all counts are counters). Sep 28 at 4:11
• @John Kormylo I tried \the\Hy@pagecounter in each page of my article, and they all typeset 0. As I don't fine related description about the count \Hy@pagecounter in the manuel, would you provide with an example or answer to illustrate how to use it?
– lyl
Sep 28 at 9:04

Using the new hook facility provided by the LaTeX kernel to calculate the current abs. page number and to add the watermark:

\documentclass{article}

\usepackage{geometry,fancyhdr}
\geometry{showframe}
\pagestyle{fancy}

\AtBeginDocument{\xdef\currentPageNumber{1}}

\chead{Current Physical Page Number is: \currentPageNumber}

\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \currentPageNumber
\AddToHookNext{shipout/background}{% upper left page corner coordinate is (0,0)
\unitlength=\paperheight
\put(0,-0.5){\makebox[\paperwidth][c]{\currentPageNumber}}
}

\clearpage
sencond page\par current absolute page number is: \currentPageNumber

\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \currentPageNumber

\clearpage
fourth page\par current absolute page number is: \currentPageNumber

\clearpage
fifth page\par current absolute page number is: \currentPageNumber
\unitlength=\paperheight
\put(0,-0.5){\makebox[\paperwidth][c]{\currentPageNumber}}
}
\clearpage
sixth page\par current absolute page number is: \currentPageNumber
\end{document}


You only need to add one to the counter:

\documentclass{article}
\usepackage{geometry,fancyhdr}
\geometry{showframe}
\pagestyle{fancy}

\chead{Currrent Physical Page Number is: \abspagenumber}

\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber

\clearpage
sencond page\par current absolute page number is: \abspagenumber

\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber

\clearpage
fourth page\par current absolute page number is: \abspagenumber

\clearpage
fifth page\par current absolute page number is: \abspagenumber

\clearpage
sixth page\par current absolute page number is: \abspagenumber

\clearpage
\pagenumbering{Alph}
seventh page\par current absolute page number is: \abspagenumber
\clearpage
eighth page\par current absolute page number is: \abspagenumber\par

\clearpage
nineth page\par current absolute page number is: \abspagenumber
\end{document}

• Is there a similar command readily available for the total page count (last page shipout #) of a document? Sep 28 at 8:35
• @AlexG \PreviousTotalPages, see ltshipout-doc.pdf Sep 28 at 8:37
• @AlexG we don't reserve the good stuff only for us ;-) Sep 28 at 8:49
• @lyl You may do \newcommand{\abspagenumber}{\the\numexpr\ReadonlyShipoutCounter+1\relax}, but updating your TeX system is much better. Sep 28 at 9:14
• @lyl I must correct myself. Since \ReadonlyShipoutCounter is incremented only after the page has been shipped out, its value should be the same in both the page body and during shipout, hence starting with zero for both. Sep 28 at 12:51

Still there, but not longer default.

\documentclass{article}
\usepackage{geometry,fancyhdr}
\geometry{showframe}
\pagestyle{fancy}
\usepackage[hypertexnames=false]{hyperref}

\makeatletter
\Hy@pagecounter=1
\newcommand\abspagenumber{\the\Hy@pagecounter}
\makeatother

\chead{Currrent Physical Page Number is: \abspagenumber}
%\lhead{Currrent Physical Page Number is: \abspage}
\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber
\clearpage
sencond page\par current absolute page number is: \abspagenumber
\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber
\clearpage
fourth page\par current absolute page number is: \abspagenumber
\clearpage
fifth page\par current absolute page number is: \abspagenumber
\clearpage
sixth page\par current absolute page number is: \abspagenumber