Okay, I played around a bit more and came up with a solution, though a rather hacky solution.
First attempt - pdf_update_command + Okular
This does not work fully, as it will always jump to the beginning of the file, after reloading. For the sake of completeness, I add it anyway.
In Okular turn off automatic reload by "Settings" -> "Configure Okular" -> Turn off "Reload document and file change".
Change the .latexmkrc file to:
$pdf_previewer = 'start okular --uniuqe %S';
$pdf_update_method = 4;
$pdf_update_command = 'okular --unique %S';
This tells latexmk that it should execute the pdf_update_command after it finished updating the pdf file. What does work, the document in Okular is visible all the time during compilation and is reloaded on completion. Unfortunately, when the update command is executed, you'll jump to the beginning of the document. That is not what I want.
Second attempt - pdf_update_command + cp
As the previous attempt did not work out, I am now going with a hackier solution. For this the document reloading has to be turned on in Okular.
The .latexmkrc should look like this:
$pdf_previewer = 'start okular';
$pdf_update_method = 4;
$pdf_update_command = 'cp ~/path/to/doc.pdf ~/path/to/doc_preview.pdf';
This copies the actual document file to a preview location. So Okular needs to be opened for this preview file (and for the other file you have to close it manually). This is surely not ideal, but it does what I want:
- Updating the pdf file in the background
- Updating only when the file is ready
- Works across ssh
Update (thanks to Sam De Meyer):
If you do not want the previewer to start, leave the $pdf_previewer empty:
$pdf_previewer = ''
If you on the other hand rather like to close a window than open one, it is possible to specify the 'doc_preview.pdf' together with the original pdf. I have not found a way, to only open the second pdf file:
$pdf_previewer = 'start okular ~/path/to/doc_preview.pdf'
PS: This works with any editor that automatically reloads files, as e.g. evince.