2

I'd like to print a sentence like this:

"written upon this page and the n preceding pages of paper"

where n is the number of pages before this page.

\thepage gives me the current page number, so really I just want \thepage - 1. I've been trying to look at performing some math in LaTeX, but I can't seem to find anything.

I've also looked at the lastpage package (which could work, because this sentence is actually going on the last page of the document), but I'd still need to subtract 1 from it.

EDIT:

Thanks to kan/gekkostate, here's the result that does exactly what I wanted:

...
\newcounter{precedingpages}
\setcounter{precedingpages}{\thepage}
\addtocounter{precedingpages}{-1}
written upon this page and the \theprecedingpages{} preceding pages of paper
...
3
  • 2
    You could define a new counter that is triggered whenever \thepage is and \addtocounter{newcounter}{-1}.
    – kan
    Commented May 6, 2013 at 17:41
  • 1
    @Kan I was just about to recommend that!
    – Jeel Shah
    Commented May 6, 2013 at 17:44
  • @kan Totally works! Can you submit an answer and I'll upvote/give you the answer for it? I've edited my question with the final result.
    – aardvarkk
    Commented May 6, 2013 at 17:44

1 Answer 1

3

Using \thepage might produce undesired results due to the asynchronous nature of page building mechanism. Using a \label, \ref approach can prevent the undesired results:

\documentclass{article}
\usepackage{refcount}
\usepackage{lipsum}

\newcounter{abc}

\newcommand\prevtopage{%
  \stepcounter{abc}
  \label{page\theabc}written upon this page and the  \the\numexpr\getpagerefnumber{page\theabc}-1\relax\ preceding page(s) of paper.}

\begin{document}

\prevtopage
\clearpage
\prevtopage

\end{document}
2
  • +1 This answer is nice because it looks like I could reuse the command all over the document as a one-liner without having to keep defining counters like my current approach.
    – aardvarkk
    Commented May 6, 2013 at 17:50
  • @aardvarkk yes, you can resuse \prevtopage as many times as you wish, but another (main) advantage is that it will give always the right results, unlike the \thepage approach. Commented May 6, 2013 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .