rzukic / zed-latex

33 stars 4 forks source link

Auto PDF preview config #31

Closed lnay closed 3 weeks ago

lnay commented 1 month ago

Listening to feedback from friends (and others), people do not want to set up a bespoke configuration for PDF preview and forwards/inverse search when starting out using this extension. The out-of-the-box experience should aim to be comparable to popular solutions such as Overleaf because that is the expectation these days. Then if the user requires something more bespoke, they can visit the wiki and create a custom configuration which should not be overriden by this extension.

This PR checks if any of the PDF viewers documented here are on PATH, or are in the standard location. If one is found, this fact is recorded. Then when workspace configurations are requested by texlab, if none of the user configurations define texlab.forwardSearch then this is automatically set with values corresponding to the detected PDF viewer to enable forwards/inverse search as much as possible.

Some PDF viewers cannot have the inverse search set from the CLI so will need the user to adjust settings themselves. The user would need to visit the wiki on their own to find this out as there is no way to notify the user from the extension.

If texlab.forwardSearch is automatically configured, then the extension will also enable the options texlab.build.afterSave and texlab.build.forwardSearchAfter unless they are explicitly turned off by user settings. This is to match the default experience in other LaTeX IDEs. However these two settings (texlab.build.afterSave and texlab.build.forwardSearchAfter) are not automatically enabled if texlab.forwardSearch is not auto-configured, notably when none of the PDF viewers are detected. This is because builds would be triggered without visual feedback (pdf preview), potentially leading to confusion and issues with stuff happening in the background that the user is not aware of.

This isn't fully tested but still opening this PR now for any opinions or feedback on the topic as this change is opinionated.

lnay commented 1 month ago

Qpdfview

lnay commented 1 month ago

zathura

Works fine with inverse-search working out of the box

lnay commented 1 month ago

Okular

lnay commented 1 month ago

SumatraPDF

Not implemented, Zed is not released for windows anyway.

lnay commented 1 month ago

Skim

Tested on intel mac, forward-search works correctly, and inverse-search requires adjusting skim settings.

lnay commented 1 month ago

Park this for now, Zed currently does not send textDocument/didSave RPC requests to texlab anymore for some reason, making this PR useless. Coming back to this after Zed is fixed.

zayneLKC commented 1 month ago

@lnay, what other setting adjustments did you need to do to make inverse search with Skim work? Perhaps Issue #30 is helpful.

Also for my understanding, would zed <file>:<line number> in the Skim > Settings > Sync Command section work instead of zed and '%file':'%line' in the Command and Arguments section (respectively)?

I'm new to publicly maintained repos, so please let me know if this is not an appropriate comment!

lnay commented 1 month ago

The setting I used was almost the same as that issue 30

I do not know if putting the arguments in the command also works, that will depend on how skim was written.

The quotes are so that any spaces in the file name do not split it into separate arguments (that's why %line does not need it). Single quotes have a similar but slightly stronger effect, I expect either will work.

lnay commented 1 month ago

I see where the question comes from, in the wiki it says what it says as generic advice. In the skim settings, it says somewhere that %file and %line in the inverse search command will be substituted appropriately. And different PDF viewers may use slightly different markers to substitute the file name and number. Note that the inverse-search command is executed by the PDF viewer, not Zed itself.

lnay commented 4 weeks ago

Park this for now, Zed currently does not send textDocument/didSave RPC requests to texlab anymore for some reason, making this PR useless. Coming back to this after Zed is fixed.

It's all fixed now

lnay commented 3 weeks ago

New issue: zed_extensin_api::Worktree::which is no longer finding executables in /usr/bin/ (which should be in path for any environment Zed should reasonably set up).

lnay commented 3 weeks ago

Possibly related issue: https://github.com/zed-industries/zed/issues/19779

lnay commented 3 weeks ago

All seems fine now