I'm working on a larger PDF file produced by kile/pdflatex which takes about 30 seconds to build. When I initiate a build in kile, the PDF document gets cleared immediately (the PDF file is truncated) and only shown again 30 seconds later after the build is finished and the new PDF file complete. Alternatively I can switch off auto-reload in okular, but have to reload the document manually later on. Instead I'd like okular to reload the document automatically, but only when the build is finished. My guess what is happening in auto reload mode currently is the following: 1) PDF file is ok, shown in okular 2) Initiate build, pdflatex truncates pdf 3) okular notices file change, tries reload. File is not complete, nothing shown 4) pdflatex writes some chunks to the file. 5) The pdf might not be complete, back to 3). Otherwise okular displays the new file What I'd find more convenient would be 1) PDF file is ok, shown in okular 2) Initiate build, pdflatex truncates pdf 3) okular notices file change, tries reload. File is not complete. Old file is still shown, along with a "file vanished on disc" indicator in the user interface 4) pdflatex writes some chunks to the file. 5) The pdf might not be complete, back to 3). Otherwise okular displays the new file, removes "file vanished on disc" indicator The main difference is that I can continue reading the (outdated, but still useful) PDF while it is updated. Is that doable or would that break e.g. loading of other pages which are not in memory?
You might want to get some inspiration from this HowTo: http://linuxunderthesky.blogspot.de/2011/09/synctex-in-kile-and-okular.html
How do we know the file is finished changing?
(In reply to comment #0) > What I'd find more convenient would be > 1) PDF file is ok, shown in okular > 2) Initiate build, pdflatex truncates pdf > 3) okular notices file change, tries reload. File is not complete. Old file > is still shown, along with a "file vanished on disc" indicator in the user > interface > 4) pdflatex writes some chunks to the file. > 5) The pdf might not be complete, back to 3). Otherwise okular displays the > new file, removes "file vanished on disc" indicator > > The main difference is that I can continue reading the (outdated, but still > useful) PDF while it is updated. Just to relate to this, the live preview feature in the upcoming version 3.0 of Kile will only reload the PDF file once LaTeX is finished. Hence, this problem won't occur anymore.
(In reply to comment #1) > You might want to get some inspiration from this HowTo: > http://linuxunderthesky.blogspot.de/2011/09/synctex-in-kile-and-okular.html There is also no need to modify the configuration of the tools as it's described there - just choose the 'Modern' configuration of (PDF)LaTeX.
(In reply to comment #2) > How do we know the file is finished changing? Currently there seem to be a couple of load attempts by okular while the file is being written, each of them failing. So I'd try with "the file is finished when it can be opened correctly". I know too little about PDF internals though to judge if that is sane.
What if the dude Ctrl+C the pdflatex process or the generated pdf is never valid?
Then you're left with a stale opened PDF file, the same as if you had configured okular not to do automatic reloading at all.
But that is wrong, you asked your pdf to be reloaded and it hasn't been reloaded (to it's broken state) So if that happens you may close okular, attach the pdf to your boss and then discover you sent a broken pdf
I am not really sure, but I think Nepomuk developers found a way to only get notified when a file is finally closed after writing (e.g. download finished), instead of whenever it is modified.
Nepomuk friends, can anyone conform Christoph's comment?
inotify has a 2 modification events - IN_MODIFY - Emitted anytime a file is modified IN_CLOSE_WRITE - when a file that is opened with a write flag is closed regardless of the modifications. For Nepomuk we only use the IN_CLOSE_WRITE signal and then manually check if the mtime of the file has changed. Many programs open files under write mode even when no modifications are to be made -eg Taglib. Some programs, such as KTorrent, are even worse and keep opening and closing files with write flags when seeding. I had a look at KDirWatch and it only checks for the IN_MODIFY signal. I'm not sure how one would go along implementing IN_CLOSE_WRITE. Nepomuk uses inotify directly cause of our special requirements instead of going through KDirWatch.
Anything that means not using KDirWatch or something cross platform is not acceptable
It looks like this is still around. I looked into KDirWatch and it seems it only has support for file changes (i.e. the "dirty" signal), so it is impossible to know when the file is closed for writing (lua/xe/pdflatex all seem to write multiple chunks and close the file now and then as well). Wouldn't it work if okular shows a warning when the pdf-file changes, and waits with updating the graphical layout until it has successfully loaded the new pdf-file? I mean a warning along the lines of in big red letters "The current file is corrupt, showing the last known good state from %time". This behavior should only be the default for "greedy"-mode as well I think, since those of us who would benefit from it are probably all using greedy anyhow and it could, as previously stated, cause some confusion that the pdf shown is not the exact version on the disk at that moment. I'm currently working around this with a last `cp file.pdf file-view.pdf` in my makefiles, so a fix to this issue is, at least for me, a matter of convenience.
That means a lot of architectural changes, to be able to open a file, you must close the file, that's how Okular works, if you want to do what you suggest you need to be able to not do that. Is it possible? probably