12

When I am writing a TeX document, I use a setup to automatically recompile my *.tex files into a pdf as soon as a source file changes (using latexmk). So I put a terminal with nvim on one side of the screen and okular with the pdf output on the other side of the screen.

The annoying thing is that okular flashes/blinks every time the pdf updates. This is especially noticeable when I have glossaries + references + index. Okular will then flash 3 to 5 times depending on what has changed in the *.tex source, and I find this really distracting. Is there any way to disable this flashing behavior?

5
  • 3
    Settings -> Configure Okular -> General -> Program Features -> untick "Reload document on file change". Then press F5 to reload pdf only if desired.
    – 林果皞
    May 7, 2016 at 20:18
  • Well, this solves the flashing problem but introduces a new problem, now I have to press F5 every time I want to see an update. I was hoping there was some way to auto-reload the file without the distracting flash, but maybe this is not possible with okular. Anyway, thx for temporary workaround. May 7, 2016 at 21:49
  • 1
    The file gets updated a number of times during the build process. Each time the file gets updated, Okular refreshes it. Okular doesn't seem to have an "if it updates, wait N seconds to see if it updates again before refreshing" option. Jul 6, 2018 at 17:41
  • Even this was asked a while ago, I wanted to point out, evince behaves maybe more like what you want. If you found another good solution in the meanwhile, let us know. I have exactly the same problem... (and can't use evince, as it has problems with x-forwarding)
    – Exocom
    Aug 6, 2018 at 5:45
  • I think mupdf doesn't flash (or it's much less noticeable) pdf - How to make mupdf automatically refresh a document - Unix & Linux Stack Exchange
    – user202729
    Feb 25 at 16:22

1 Answer 1

3

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:

  1. Updating the pdf file in the background
  2. Updating only when the file is ready
  3. 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.

2
  • 1
    Hi, the 'cp' trick might work. Do you actually need to do 'start okular' in the 'pdf previewer'. Maybe you can just leave it empty or specify a command that does nothing? Then all you have to do is open okular on the copy the first time you compile. Wouldn't that solve the problem? Aug 6, 2018 at 7:20
  • Yes, leaving it empty does the trick of not starting okular. Thanks. Will update the answer (as well with an addition that starts the previewer for both files). The whole thing, that the update of a file only appears after the compiling is finished helps greatly. I am just writing a bigger thesis, where this does in come really handy.
    – Exocom
    Aug 7, 2018 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .