[pdftex] Re: Forward looking object references

Laurent Siebenmann Laurent.Siebenmann at math.u-psud.fr
Sun Mar 23 01:44:28 CET 2003



Hi Igor

 > I am trying to create a PDF document  (DVI is not a requirement) that would
 > show the total number of pages on each page (e.g. PAGE X OF Y), and do it in
 > one front-to-back linear pdfTeX pass! 

 >...

 > Below please find the PDF example that was initially created
 > with pdfTeX, and then edited manually. This example shows that
 > in PDF we can use forward references! Please check out object
 > 1000. I believe that this document can be quite easily generated
 > in one pass -- the object (xform) is at the very end of the file
 > -- we do have necessary information by that time.

I agree entirely.

Since PDF has objects and foreward references, pdftex should
endeavor to introduce powerful primitives to take best advantage
of these features.  But who can imagine specs for the new
primitives...?

DVI lacks these features, but in compensation allows easy DVI
post processing.  

I now explain why one can expect DVI postprocessing to go orders
of magnitude faster than TeX.  The idea is to typeset page n as
two pages:- number n and number N+n where N is the total (final)
number of pages; the second manifestation contains the
pagenumbering (at the DVI level) --- coming from a dimensionless
box

        Page 101 of 67,822                  (*)

whose insertion point is top-left (bop). By the time the
auxiliary page N+n is typesetset the final pagetotal 67,822 is
known, so there is no problem anymore for TeX to, for example,
right adjust this fragment at the bottom of the page as is
common practice. It remains to overlay page N+n onto page n by
DVI postprocessing.

Can the postprocessing be almost instantaneous? Would one not
expect to have to parse the DVI file? Or to rewrite masses of
data fiddling extensively with the DVI's backpointers?

For your present problem, the answers are yes, no, no -- the
best possible.  The basic observation is that there is a small
'a priori' bound on the number of DVI opcodes needed to describe
(*) on page N+n.  We can just reserve that much DVI space in the
output for page n using an 'ad hoc' \special{...} command.  Then
the postprocessing first replaces the \special{...} by a
sequence of null opcodes (nop's).  Then it overlays the DVI
description of (*) in page N+n onto some of those nop's in page
n. Finally pages N+1,N+2,... are deleted and the trailer
adjusted accordingly. That's it! TeX runs just once, piping to
the postprocessor. The first N DVI backpointers are untouched
and essentially no parsing is done.

This schematic solution may give hints for equally fast
and painless PDF solutions.

Cheers

Laurent S.





More information about the pdftex mailing list