Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some issues with TeXShop previewer #2835

Open
griffinwxk opened this issue Nov 23, 2023 · 7 comments
Open

Some issues with TeXShop previewer #2835

griffinwxk opened this issue Nov 23, 2023 · 7 comments

Comments

@griffinwxk
Copy link

Description

I've been trying out various previewers recently due to dissatisfaction of them (unrelated to vimtex itself):

  • Skim has to be launched by neovim for inverse searching to work, but since I use it as my main pdf viewer for papers it's not convenient.
  • zathura is great overall as a previewer, but trackpad scrolling and keyboard scrolling have vastly different speed so no matter what it's always janky.
  • sioyek is not polished enough, specifically its font rendering is buggy for multiple displays with different dpi

So it leads to me trying out configuring TeXShop. As it turns out, vimtex's setup seems not working for me. I dug into the source and extracted the AppleScript code and tested it. Maybe it's due to OS version (I'm on Sonoma), I'm very surprised to find out that it has syntax errors.

I modified the code and finally got it working and it seems good enough. During my testing I also found out some shortcomings of the original code:

  • Notably it will only do forward searching for the "front most document" opened by TeXShop. So if I have multiple projects open, only one of them at a time can have forward searching. I fixed it on my machine by checking the corresponding pdf everytime instead of using the front most one.
  • When synctex is set, the current code also opens tex file in TeXShop and launches TeXShop's compiler for some reason, which seems completely unnecessary? I deleted the line and it seemed perfectly fine.
  • Related to above, when synctex is set, unlike other viewing method like Skim, which simply appends some command to include synctex, the code for TeXShop overwrites it with new command. So the behavior is weird: no synctex => launch previewer normally; yes synctex => launch tex file and compile. I don't know why it was coded this way.

The reason I didn't create a PR is that I don't know if the original author had other intentions and if there is compatibility issues across macos versions. And I'm also not quite familiar with PRs (only done a very tiny one before). If anyone can confirm this issue I'd be happy to submit a PR later.

Steps to reproduce

Set g:vimtex_view_method to "texshop", and launch viewer.

Expected behavior

TeXShop opens with the pdf only, and forward/inverse searching working.

Actual behavior

As is, nothing shows up. I described several other issues after testing the code in the description.

Do you use a latexmkrc file?

Yes

VimtexInfo

It's irrelevant as I was able to pin the error to the AppleScript code in texshop.vim
@griffinwxk griffinwxk added the bug label Nov 23, 2023
@lervag
Copy link
Owner

lervag commented Nov 25, 2023

So it leads to me trying out configuring TeXShop. As it turns out, vimtex's setup seems not working for me. I dug into the source and extracted the AppleScript code and tested it. Maybe it's due to OS version (I'm on Sonoma), I'm very surprised to find out that it has syntax errors.

I don't use MacOS myself, so I'm not really acquainted with the osascript syntax.

I modified the code and finally got it working and it seems good enough.

I would be happy to consider a PR!

The reason I didn't create a PR is that I don't know if the original author had other intentions and if there is compatibility issues across macos versions.

The original author is @michaelliebling, so I'll ping him and allow him to comment on this himself. But I would not be surprised if your suggested updates would be more than welcomed!

And I'm also not quite familiar with PRs (only done a very tiny one before). If anyone can confirm this issue I'd be happy to submit a PR later.

I'll be glad to help!

@griffinwxk
Copy link
Author

Thanks for the reply! I guess I'll wait a bit then. I'm currently busy anyway so maybe early to mid December will be a good time.

@michaelliebling
Copy link
Contributor

Great to hear that someone else is using the TeXShop - Vim combo on macOS!

vimtex's setup seems not working for me.

I'm sorry to hear that things are not working for you. I can confirm that Vimtex is still doing forward and inverse searches as expected on macOS Sonoma 14.0, with MacVim r178 (Vim 9.0.1897), a fresh copy of vimtex cloned into ~/.vim/pack/lervag/start/vimtex and a minimal .vimrc:

filetype plugin on
let g:tex_flavor='latex'
let g:vimtex_view_method='texshop'
let g:vimtex_view_automatic=0
let g:vimtex_view_texshop_activate=1 

Please note the last preference, g:vimtex_view_texshop_activate, which must be set to 1 if you want the TeXShop window to pop-up to the front when you call :VimtexView. The default value is 0, which implies TeXShop will update the page but won't bring the window to the front (= it won't 'steal' the focus away from Vim). That option is less distracting if you have a large screen with all windows visible side-by-side and you prefer not to leave the Vim window. But depending on how the windows are arranged on the screen, it may appear as if nothing is happening. Maybe the default value should be set to 1 to avoid the possibility for new users to be confused by this (lack of) behavior. I don't recall what the default is for other combos that have that feature.

When synctex is set, the current code also opens tex file in TeXShop and launches TeXShop's compiler for some reason, which seems completely unnecessary? I deleted the line and it seemed perfectly fine.

To avoid having the .tex file open in the TeXShop's Editor, I check TeXShop -> TeXShop -> Settings... -> ☑️ Configure for External Editor. The TeXShop compiler should only run if no up-to-date PDF that corresponds to the .tex file already exists. Only opening the pdf in TeXShop as you suggest could be an alternative but then, are you still able to re-compile the file by TeXShop and do inverse searches from TeXShop's compiler window when TeX errors arise? This is a really nice feature, which I think is worth preserving.

Related to above, when synctex is set, unlike other viewing method like Skim, which simply appends some command to include synctex, the code for TeXShop overwrites it with new command. So the behavior is weird: no synctex => launch previewer normally; yes synctex => launch tex file and compile. I don't know why it was coded this way.

Can you point to the part of the code which you think is responsible for this? (Where do you 'set' synctex?) I suspect this is linked to using TeXShop without the external editor setting set but can't be sure from what you write.

Notably it will only do forward searching for the "front most document" opened by TeXShop. So if I have multiple projects open, only one of them at a time can have forward searching. I fixed it on my machine by checking the corresponding pdf everytime instead of using the front most one.

If multiple documents are open in TeXShop, I confirm that the current code will bring up the front document (assumption that only a single document is open). It is probably possible to cover other cases but I never really had a use for them. I'd be happy to test out a fork that provides these features.

I dug into the source and extracted the AppleScript code and tested it. Maybe it's due to OS version (I'm on Sonoma), I'm very surprised to find out that it has syntax errors.
I modified the code and finally got it working and it seems good enough.

Can you clarify which program is reporting syntax errors and what these errors are?

What resembles AppleScript code in vimtex/autoload/vimtex/view/texshop.vim certainly cannot be copy-pasted and run as-is by Apple's Script Editor: the AppleScript code is created by Vimtex on the fly. The generated AppleScript code will vary depending on what options you set in your .vimrc.

Again, happy to test alternatives!

@griffinwxk
Copy link
Author

griffinwxk commented Nov 26, 2023

Thanks for the detailed reply! Yeah there's a lot to cover so I'll go through them one by one, in (possibly) multiple comments I'm afraid as I can't reply all at once. I'll start with ones that I find important then.

Can you clarify which program is reporting syntax errors and what these errors are?

Can you point to the part of the code which you think is responsible for this?

There are two for me, one more obvious and one more subtle.

  • Line 55, if (count of theDocs) > 0 then revert theDocs: it seems changing to revert(theDocs) is the correct one, otherwise it reports error. This part seems never run because lines 90-92 override l:script (which addresses your second question above.
  • Line 75: I don't know if it's due to the subtle difference between vim and neovim, but l:sourcefileFull is surrounded by extra single quotation marks (iirc) for me. After deleting shellescape in its initialization (so only expand), it fixes for me.

BTW, Could you paste your l:script by printing it?

I check TeXShop -> TeXShop -> Settings... -> ☑️ Configure for External Editor

I did too but I don't know why it still pops up. I also set the hidden option as instructed.

are you still able to re-compile the file by TeXShop and do inverse searches from TeXShop's compiler window when TeX errors arise?

The last file I tested using the original vimtex code (i.e. without my modification) was part of a big project and TeXShop reports some "undefined macro" error, possibly due to not being able to determine the project root correctly. But I didn't investigate that further because I would not want TeXShop to do the compilation. Two compilers at once is perhaps more error-prone. At the time I simply deleted the line for the .tex file and moved on to test other parts of the code.

Maybe the default value should be set to 1 to avoid the possibility for new users to be confused by this (lack of) behavior.

No I think it should stay 0. Window focus is not my problem. I do use large screens with tiling window manager so changing focus will be less efficient. Tbf I think most people who use (neo)vim for production are probably savvy enough to check manually if the focus doesn't change automatically.

I'd be happy to test out a fork that provides these features.

Yeah I do have some temporary code that does work. Will definitely put it in a PR after the issues above are sorted out.

@lervag
Copy link
Owner

lervag commented Jan 1, 2024

I'm curious, should I leave this issue open or should I close it? I'm not planning to do any action myself, as I don't even know where to start. But if it makes sense I'll leave it open for you guys to continue discussing and possibly resolve through a PR?

@griffinwxk
Copy link
Author

Hi Karl, sorry for letting you hanging. I have been busy with my writings and perhaps still will be for a while so I don't have time for PR yet. I have temporarily reverted back to zathura seeing it's the most stable for me. Seems no one else can confirm my issue with the current code, and I know it looks like a lot of work for marginal gain due to how niche TeXShop is.

You can close it if you want, and maybe if someone else encounter the same problem they can reopen it. I realize my use case may be too niche for most people as I write complex LaTeX projects (sometimes multiple branches for different submission requirements) so maybe it's best for me to just write custom rules for previewer since VimTeX also supports that.

@lervag lervag added help-wanted os-mac MacOS / OSX labels Jan 2, 2024
@lervag
Copy link
Owner

lervag commented Jan 2, 2024

I don't mind keeping it open if that may be of help to you or others that want to follow up on this. I've updated the tags to make it more clear that I'm not planning to work on this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants