3

Is there a way to get the number of pages shipped out so far? To be clear, I want to count "physical" output; I'm not interested in logical page numbers we typically find in the footer or header.

My current implementation simply hacks into \shipout, as shown below, but this will not work if some package ships out via \primitive\shipout (as, ahem, my package does). So to rephrase the question once more, I need to count the number of times the \shipout primitive was called.

\def\shipout{%
  \global\advance\mmz@realpage1
  \mmz@orig@shipout
}%

I'm aware of the everyshi package and I plan to use it if my question ends up with a negative answer — so that the half-working hack is at least performed in an "official" way — but as I only need to count the number of output pages rather than modify them in any way, I thought to ask if there's a less invasive and more precise way to do this.

At the end of the day, I'm looking for a solution that would work across engines and formats, but at this point, I welcome hints for a partial solution just as much.

Background: I'm developing an externalization package memoize, currently available at GitHub. The package externalizes all graphics in a single compilation, and it achieves that by dumping the externalized pages into the document itself. In the next stage, these pages are separated from the regular output, and to do that, I need to know which pages these are, in terms of a real, physical page number.

  • 3
    The next LaTeX version will contain shipout hooks which are intended to replace the hooks from everyshi and atbegshi. There will be also a counter. If you back into the primitive, it could clash. – Ulrike Fischer Jul 15 at 6:10
  • 1
    There is no internal counter associated to the primitive \shipout. So either you cooperate with packages that change it or you're doomed. – egreg Jul 15 at 9:30
  • 1
    Thanks to both. @egreg, if you copy-paste this into an answer, I'm happy (well, unhappy, to you know what I mean) to accept it. – Sašo Živanović Jul 16 at 11:49
3

I'm afraid there is no internal counter that's stepped at each \shipout operation. If it is only called by the output routine, then one can take care of it with a counter, that's incremented when a page is actually shipped out.

In your case this is out of the question, so one has to hook in \shipout by redefining it. Since other packages do, the important thing is to cooperate with them. Currently, the most reliable package is atbegshi.

Kernel hooks are planned in the near future.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.