izuzak / atom-pdf-view

Support for viewing PDF files in Atom.
https://atom.io/packages/pdf-view
MIT License
106 stars 30 forks source link

Multiple reloads when compiling LaTeX #161

Closed AustenLamacraft closed 6 years ago

AustenLamacraft commented 7 years ago

When building a LaTeX document with the latex package the pdf view reloads twice or even three times.

This doesn't happen with a short document without errors, but I don't know whether it's down to the errors or the length.

OS X 10.11.6 Atom 1.12.7 pdf-view 0.54.0

izuzak commented 7 years ago

Hi, @AustenLamacraft. Can you clarify what kinds of errors you're referring to? You said:

This doesn't happen with a short document without errors, but I don't know whether it's down to the errors or the length.

But there's no mention of any errors before that.

In any case, this package watches the PDF file it's displaying and reloads it if there are any changes. So, if the PDF file that's being generated is changing (e.g. the process that's generating it is incrementally building it, thus changing it) -- then it will be reloaded. That's expected behavior. Could you perhaps clarify what you expected to see instead?

recluze commented 7 years ago

PDFs are indeed created "incrementally" by latexmk (the tool typically used by latex builders). So, yes, this is expected behavior. I think you should explore latexmk options to create an intermediate file before pushing a final PDF to the output.

nicola-gigante commented 7 years ago

You are correct that this is the "expected" behavior, since LaTeX compilation involves multiple passes, and at each pass the pdf is changed. However, especially with long documents (and not so long ones, actually, depending on the hardware) where the load time is noticeable, this behavior is very annoying. I used pdf-view for a while and currently I'm not using it anymore precisely for this reason.

Thus, while the current behavior is technically correct, I think something better can be achieved. Here is an idea. A settings switch to disable the automatic reload itself would do the trick. Latex Atom plugins (latextools at least, which is the one I use) by themselves already open the resulting pdf on a "viewer" when the pdf is ready. E.g. if the selected viewer is pdf-view instead of an external program, and no pdf is currently open, a new tab is open with the pdf file displayed in it. I suppose this happens also when the tab is already opened, and by the way, this is currently causing yet another useless reload, because pdf-view reloads the pdf when it changes and then is asked to reload it again. This means that, by giving the option of disabling the auto reload, the reload would happen only once, at the end, when the latex plugin requests it.

I think this is feasible and easy. What do you think?

izuzak commented 7 years ago

Thanks for sharing your thoughts, @nicola-gigante

I think this is feasible and easy. What do you think?

I don't have time to work on that myself, but if you'd like to give it a try -- I'd be happy to review a pull request.

nisargjhaveri commented 6 years ago

Latex Atom plugins (latextools at least, which is the one I use) by themselves already open the resulting pdf on a "viewer" when the pdf is ready. E.g. if the selected viewer is pdf-view instead of an external program, and no pdf is currently open, a new tab is open with the pdf file displayed in it. I suppose this happens also when the tab is already opened, and by the way, this is currently causing yet another useless reload, because pdf-view reloads the pdf when it changes and then is asked to reload it again. This means that, by giving the option of disabling the auto reload, the reload would happen only once, at the end, when the latex plugin requests it.

From what I can see they (both latextools and latex) always call atom.workspace.open with the pdf file, which works as expected when the file is not already open. But if the pdf is already open in some other tab, from what I can understand, atom.workspace.open doesn't give any signal to pdf-view package and the pdf is not updated if auto reload is turned off.

To resolve this issue properly, I think, pdf-view needs to provide an API to update pdf. And the latex packages need to call that it the pdf is already open and run foreardSync once the pdf is updated to properly synchronise everything.

Suggestions?

nisargjhaveri commented 6 years ago

To resolve this issue properly, I think, pdf-view needs to provide an API to update pdf. And the latex packages need to call that it the pdf is already open and run foreardSync once the pdf is updated to properly synchronise everything.

Alternatively, we can maybe also listen to atom.workspace.onDidOpen and treat that as signal that someone wants to open an updated pdf, when auto reload is off.

izuzak commented 6 years ago

Thanks for thinking of other approaches, @nisargjhaveri :bow: If you'd like to try and implement one of those approaches and see if it solves the problem for those other plugins -- I'd be happy to review the PR!

sbelharbi commented 5 years ago

Hello, I came across the same issue (the 'blinking' of the pdf-view when compiling using latex). As it was mentioned above, it is an expected behavior that pdf-view updates the pdf when compiling. However, it is annoying, and from user perspective, it is not necessary to show the result of every step of the compilation. I understand that this is not the issue of pdf-view nor the latex compiler since they do both their job. @recluze mentioned using a temporary file to store the intermediate changes of the pdf before finally updating the pdf file. I think it is a reasonable solution.

I read this update where auto-reload on update option is added. However, when unchecked, no update to pdf is done, which is the job. I do want to see the final changes of the pdf.

I don't know if I missed something in the conversation, but it would be better if pdf-view updates the pdf only when the compilation is done and not after each intermediate step (since latex does many updates).

I use latex package for compilation.

Any suggestions on how to fix this (probably changing the configuration of atom, latex, pdf-view, ... )? Thanks

nisargjhaveri commented 5 years ago

Disable "auto-reload on update" and set latex to open file using pdf-view when compilation is done.

I used the two packages with this config for some time, and it worked perfectly. Unless something is changed recently. I no longer use this as much.

204 enabled this scenario.

sbelharbi commented 5 years ago

Thanks! it did the trick! Disabling autod-reload on update and setting latex opener to pdf-view reload ONCE the pdf at the end of the compilation AND highlights the modified part using a red graded ball instead of a red rectangle.

Thanks!