Reverse page numbering

How can one make LaTeX print the pages numbering in reverse order, in the sense that if the document in question has N pages then the first page is numbered N, then N-1, ...?

-
Out of curiosity: why do you want to do this? – Charles Stewart Nov 27 '10 at 10:58
@Charles: I'd assume it's for an (boring) continuum mechanics textbook or similarly complex discipline, so that the students have an idea how many pages are there left for them to read.. – Martin Tapankov Nov 29 '10 at 12:03
@Martin: This sounds depressingly plausible. – Charles Stewart Nov 29 '10 at 14:05
Too good question, I am that person who likes to have reverse page numbering, it is very motivating to read a book with this numbering. – Prabhanjan Naib Sep 18 '11 at 18:51
@CharlesStewart I in fact did exactly this while publishing a Hebrew-English book which opens both LTR and RTL and has continuous page numbering throughout. It was easiest to work on the two sections separately and then combine them with pdftk. I needed a way to make the page numbers on one side run backwards and continue from where the other side left off. Quite handy. – Aryeh Leib Taurog Sep 1 '15 at 12:25

Here's an idea:

1. Run the the *tex compilation as usual, and calculate the number of pages.
2. On the second run, customize the page number to be shown as TotalPageNum-CurrentPagenum+1 (calculated by a formula, that is).
3. There is no step 3.

You probably can skip doing this until your document is finished, so that this is a one-off operation.

There are so many things that might be unfeasible or outright difficult, but perhaps that could work. At least, this is not likely to be dependent on a particular document class.

-
Awesome solution – Prabhanjan Naib Sep 18 '11 at 18:50

Here's a solution you can use for book class documents. It counts down the remaining pages from \mainmatter to the last page, ignoring pages in the \frontmatter division (mainly because I didn't want to overcomplicate things with roman numbering, but still wanted to provide an answer that recognised the issue). You'll obviously need to adjust this answer for non-book class documents (article, report, etc.; memoir and KOMA class documents are probably a whole new kettle of fish for which this solution is likely to prove unsuitable).

\documentclass[twoside]{book}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{plain}
\let\oldmainmatter\mainmatter
\renewcommand\mainmatter{%
\cleardoublepage%
\oldmainmatter%
\pagestyle{fancy}%
\fancyhf{}%
}

\begin{document}
\frontmatter
\chapter{Front Matter}
\lipsum[1-10]
\mainmatter
\chapter{Chapter One}
\thispagestyle{empty}%
\lipsum[1-15]
\chapter{Chapter Two}
\thispagestyle{empty}%
\lipsum[1-10]
\end{document}

-
Will \pageref work correctly with this solution? It looks to me like the page number displayed won't match the references. – Aryeh Leib Taurog Sep 1 '15 at 13:15

You have already received good answers for your questions, but I'd like to mention another way of getting around boring page numbering, or in general, boring display of any counter. I think that sometimes it is a better idea to display a counter visually. For example, consider this five page document:

The four counters on headers and footers visually display the current page number (for some styles, they also give an indication of remaining page numbers). This is inspired by the styles used in ConTeXt presentation modules and some beamer styles.

The above example is based on a ConTeXt module that I have written. It uses metapost to draw the counters (and only works with ConTeXt MkIV). For LaTeX, one can use the same idea and use tikz as a backend.

-

Using the answer of Geoffrey Jones (+1 for his answer), for different numbering schemes you could use (some of) this:

\documentclass[twoside]{book}
\usepackage{pageslts}
\usepackage{refcount}% only necessary if some page numbering scheme
% is used more than once
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\makeatletter
\lastpageref{pagesLTS.\pagesLTS@pnc} %
(total \theCurrentPage{} of \lastpageref{LastPages})}%
%  % If each page numbering scheme (roman, arabic,...) is used just once,
%  % it is sufficient:
%\@tempcnta=\value{pagesLTS.\pagesLTS@pnc.1.local.cnt}\relax%
%  % otherwise it is necessary:
\@tempcnta=\getpagerefnumber{pagesLTS.\pagesLTS@pnc.local}\relax%
\xdef\Remaining{\the\@tempcnta}%
\Remaining{} of \lastpageref{pagesLTS.\pagesLTS@pnc} %
(in total %
\@tempcnta=\value{pagesLTS.pagenr}\relax%
\xdef\Remaining{\the\@tempcnta}%
\Remaining%
)}
\makeatother

\begin{document}
\frontmatter
\chapter{Front Matter}
\lipsum[1-10]
\mainmatter
\chapter{Chapter One}
\thispagestyle{empty}%
\lipsum[1-15]
\chapter{Chapter Two}
\thispagestyle{empty}%
\lipsum[1-10]
\newpage
\pagenumbering{roman}
\lipsum[1-10]
\end{document}

-

I actually had to do this and I found a simple solution, based on Martin Tapankov's answer, which didn't require manual intervention. Here is a minimal working example:

\documentclass[12pt]{article}
\usepackage{kantlipsum}

\usepackage[pagespersheet=1]{totpages}
\renewcommand\thepage{\number\numexpr 1+\TotSheets-\the\value{page}\relax}

\begin{document}
\kant[1-20]
\end{document}


The advantage of modifying \thepage as opposed to just changing the page number display in the header/footer is that \label and \pageref work as expected.

-