2007/6/27, David Kastrup
For example, preview-latex uses mylatex.ltx to dump the state of the TeX at \begin{document} time. Not allowing any image references (like in \savebox commands) before that point of time is a rather brutal restriction.
Why do you need it and what do you gain by using \savebox? The speed increase is most likely minimal and the document needs to read the image anyway -- unless you want to dump fragments of pdf code into the format. If we expanded the dvi model we would dump the meta information about pdf things and then undump them later. This needs code for dumping and undumping this meta information. And \immediate\pdfximage would still fail.
Again: the \AtBeginDvi command was added to LaTeX precisely in order to conserve pretypeset stuff that would otherwise get lost at a format dump.
So store the commands there. Do you really need their expansion? Don't forget: pdfTeX is one-pass, while TeX->dvips is two-pass. Best Martin