[Tex/LaTex] pdflatex preview problem: white pdf pages with only hyperref-rectangles visible during compile

pdftex

I'm having a problem, which breaks my workflow (as I'm working on a very large document, where a full latexmk run may take 10 minutes and even compiling the chapters I'm currently working on with includeonly takes one to several minutes) and I hope someone can help (maybe has seen similar things happening):

I'm working on MacOS X 10.6.8 with TeXLive2011 and with TeXShop 2.43 as editor.

Under certain conditions, I'll see a pdf preview with white pages and only the green hyperref-rectangles as long as the document is compiled with pdflatex. It looks like that:
screenshot empty pdf

  • This only seems to happen, when at least the chapters 3 and 4 of my (large) document are included. EDIT: this might be, because those chapters contain many bitmap graphics which increase file size.
  • Some pages of the pdf (e. g. the titlepage) seem to be displayed correctly all the time.
  • If only one of them is included, I can see and browse a preview of the (old) pdf all the time during compile.
  • the same thing happens in Skim.app when I open the pdf there and then compile.

remark: As soon as compiling is finished, the pdf seems to be ok!!


EDIT: to answer the questions in the comments I'll add more information.

  1. this display problem is only existent during compiling time, as soon as the pdf is ready,
    it is displayed correctly.
  2. However it is not always the case, some documents are always visible – also during compilation.

So jonalv's idea might be the solution: the pdf viewer does not keep the whole file in memory and therefore is not able to display the other pages. As it works for some files, and for others it doesn't, maybe it is a file size issue…

At the moment I'm testing to isolate the problem.

  • a sample document with my whole preamble but with nearly 300 pages of (only) blindtext and one float in it is visible all the time (PDF size 881 kB).

Best Answer

As Michael has already pointed out it is not reasonable to expect that the viewing of a volatile file (as being built) is always correct.

Nevertheless it sometimes does work and sometimes does not work and the OP wants to know the reason behind. The following is an explanation of the technicalities in the background:

The problem is related to the way pdflatex works and how file notifications are implemented in OSX (and its Mach kernel under the hood), which are used by most PDF viewers to update the view "on change".

  • pdflatex does not write the PDF file in an atomic manner, but during the compilation process more or less continuously adds bits and bytes to it.

  • The file system notices the writes to the file and sends an update notification to the monitoring PDF viewer process. It uses some heuristics to not send an update event for every single changed byte (which would be very inefficient). The common approach here is to delay the update notification until no new changes have shown up for some time (usually a couple of milliseconds).

  • If this heuristic interacts badly with the write pattern of pdflatex, the PDF viewer gets notified before the PDF is ready and tries to read a not-yet complete PDF file.

  • The problem is not bound to specific documents or document classes. However, I personally observed it especially in conjunction with larger beamer presentations and with my thesis. My assumption is that when compiling "big" documents (that require a lot of computation or generate a lot of auxiliary files), pdflatexs updates to the PDF file during compilation are less frequent, which increases the probability of a bad interaction with the file system's heuristic to send change notifiations.

PDF viewer react differently when reading an incomplete PDF file. Skim, for instance, tends to crash or to loose the notification handle to the file system, so that no further updates show up. Apparently, TexShop's internal PDF viewer is more robust against this kind of problems.

Related Question