Closed griffinwxk closed 1 week ago
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!
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.
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!
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.
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.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.
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?
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.
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.
I was having the same issue (TeXShop not even opening) using TeXShop v5.36, MacOS Sonoma 14.5, on a 2019 Intel MacBook Pro, with NeoVim v0.10.0. Fortunately @griffinwxk's fix here worked for me:
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.
After changing the two lines mentioned, then adding the bash script from vimtex.txt, I have been able to do forward and reverse syncing with TexShop. It's not perfect, but it works.
Thank you @griffinwxk!
Closing due to lack of activity nd since @ingiestein comments that there is a resolution (even if it is not perfect).
Description
I've been trying out various previewers recently due to dissatisfaction of them (unrelated to vimtex itself):
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:
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