lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.51k stars 389 forks source link

Skim viewer opens new window #2384

Closed avonmoll closed 2 years ago

avonmoll commented 2 years ago

Description

Using the vimtex_view_method = 'skim', a new Skim window opens, unless the associated output pdf is already open in a Skim instance or the Skim window is on the current desktop. Previously, if I had Skim already running (on another desktop with some other pdfs already opened in tabs), the output pdf would be opened as a tab in the existing Skim window.

Vimtex options:

let g:tex_flavor = 'latex'
let g:vimtex_compiler_method = 'latexmk'
let g:vimtex_view_method = 'skim'
let g:vimtex_view_skim_activate = 1
let g:vimtex_view_skim_sync = 1

Steps to reproduce

  1. (have Skim open already, but on another desktop)
  2. nvim -u minimal.vim minimal.tex
  3. :VimtexCompile

Expected behavior

minimal.pdf is opened as a tab on the existing Skim window.

Actual behavior

A new Skim window appears on the current desktop with a single tab containing minimal.pdf.

Do you use a latexmkrc file?

Yes

VimtexInfo

System info:
  OS: macOS 11.6.5 (20G527)
  Vim version: NVIM v0.8.0-dev+2-g08a144912
  Has clientserver: true
  Servername: /var/folders/8s/1p9l6htd1ql9qm3xncp6mhjm0000gq/T/nvimYGeF7Q/0

VimTeX project: minimal
  base: minimal.tex
  root: /Users/user/---/---
  tex: /Users/user/---/---/minimal.tex
  main parser: current file verified
  document class: minimal
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    build_dir: build
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 6
      output: /var/folders/8s/1p9l6htd1ql9qm3xncp6mhjm0000gq/T/nvimYGeF7Q/1
      cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode -pdf -outdir=build -pvc -view=none -e '$compiling_cmd = ($compiling_cmd ?
      pid: 81154
  viewer: Skim
  qf method: LaTeX logfile
ejmastnak commented 2 years ago

Previously, if I had Skim already running (on another desktop with some other pdfs already opened in tabs), the output pdf would be opened as a tab in the existing Skim window.

Do you know when the change in behavior began to better diagnose the problem? Perhaps it has something to do with the refactor in #2289, although that was a little while ago.

Here's my two cents:

The code to open Skim is, I believe, in line 57 of autoload/vimtex/view/skim.vim and its surrounding context.

The code appears to use the Application.open method from macOS's JavaScript for Automation (JXA) scripting architecture. Out of curiosity I took a look at the relevant documentation (you can take a look yourself on macOS: open Script Editor.app > File > Open Dictionary > Skim.app), and it doesn't seem like Apple exposes much functionality for opening in tabs vs. windows; I found a basic open method and that was that. In other words, the fault here may be with the limitations of Apple's JXA rather than with VimTeX.

But I use Apple only occasionally so I'm no expert here and may be missing something obvious; perhaps @clason, who contributed #2289, will know if Apple makes it easy/feasible to implement the open-a-tab-in-an-existing-window-in-a-different-desktop behavior you're interested in.

lervag commented 2 years ago

Using the vimtex_view_method = 'skim', a new Skim window opens, unless the associated output pdf is already open in a Skim instance or the Skim window is on the current desktop. Previously, if I had Skim already running (on another desktop with some other pdfs already opened in tabs), the output pdf would be opened as a tab in the existing Skim window.

I'm sorry to say I can't help directly with this issue as I don't use MacOS. Luckily, our community has other knowleadgable users! Thanks to @ejmastnak for pitching in.

In other words, the fault here may be with the limitations of Apple's JXA rather than with VimTeX.

I believe this may be true, but I'm not sure. One question for @ejmastnak (and possibly @clason): Is this issue reproducible on your end?


By the way, you can simplify your VimTeX config. Specifically, these two options are not needed (the first is not a VimTeX option, and the second is unnecessary since you are not changing from the default value):

let g:tex_flavor = 'latex'
let g:vimtex_compiler_method = 'latexmk'
clason commented 2 years ago

As @ejmastnak points out, the scripting support is limited, underdocumented, and poorly maintained (by Apple -- things can randomly break in any macOS update without warning or acknowledgment); it was already non-trivial to get the current, deliberately limited, support working. The refactor in #2289 was necessary because one of those silent changes in a macOS update completely broke the previous approach.

In any case, the previous behavior around tabs was unintended and a (for you) "happy little accident". From my cursory search on the internet, there doesn't seem to be a straightforward way to do so; every workaround I've seen involves scripting user interaction (menu selection etc.), which I do not want to do as it makes these scripts even less robust and harder to maintain.

So I'm sorry to say that this is a "wontfix" on my end...

lervag commented 2 years ago

Thanks for pitching in, @clason. I'll close the issue with tag "won't fix". But of couse, I will be happy to continue the discussion and to consider possible PR's if anyone should feel so inclined.

shivangp76 commented 4 months ago

I came across this which says to run defaults write -app Skim AppleWindowTabbingMode -string always to open pdfs as tabs instead of windows. Running that command and restarting Skim seems to do the trick. Just thought I'd drop that in here in case anyone comes across this in the future.