Hello!
I've been recently been trying out the window swallowing feature in my window-manager. As a result, when I hit <localleader>ll to compile, my vim buffer gets hidden by the pdf document. However, on opening the compiled document using <localleader>lv, my pdf viewer opens in another window and thus doesn't hamper the visibility of my vim buffer.
I understand that this is not an issue of vimtex but I was wondering if you could help me figure out if there is a way to compile documents without hiding the vim buffer (basically I wish <localleader>ll behaved as <localleader>lv in terms of the spawning of the pdf viewer. Thanks!
The difference here is that with <localleader>ll, the viewer is opened by the subprocess latexmk, while with <localleader>lv, vimtex will open the window. So, there is probably a difference in how the viewer is opened (e.g. args, etc).
To help more, I would need to see your exact vim config. Do you have any .latexmkrc config? Which system/OS? Which viewer? When you open the tex file, then do <localleader>ll - after the viewer is opened, can you also copy the output of :VimtexInfo from Vim in herE?
I don't have a .latexmk config. I use Artix Linux with zathura as my pdf viewer. Here is my init.vim:
call plug#begin('~/.config/nvim/plugged')
Plug 'lervag/vimtex'
call plug#end()
let g:tex_flavor = "latex"
let g:vimtex_view_method = "zathura"
let g:vimtex_quickfix_open_on_warning = 0
let g:vimtex_quickfix_mode = 2
let g:vimtex_compiler_method = "latexmk"
let g:vimtex_compiler_progname = 'nvr'
edit by @lervag: Simplified vimrc; removed unrelated and irrelevant stuff.
The output for :VimtexInfo:
System info
OS: Linux 5.4.54-1-lts
Vim version: NVIM v0.4.4
Has clientserver: true
Servername: /tmp/nvimQft1R3/0
vimtex project: dlf
base: dlf.tex
root: /home/ashish/documents/reports/semester-4
tex: /home/ashish/documents/reports/semester-4/dlf.tex
out: /home/ashish/documents/reports/semester-4/dlf.pdf
log: /home/ashish/documents/reports/semester-4/dlf.log
aux: /home/ashish/documents/reports/semester-4/dlf.aux
fls: /home/ashish/documents/reports/semester-4/dlf.fls
main parser: current file verified
compiler: latexmk
configuration:
continuous: 1
callback: 1
latexmk options:
-verbose
-file-line-error
-synctex=1
-interaction=nonstopmode
latexmk engine: -pdf
job: 3
pid: 3525
cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode -pdf -pvc -e '$new_viewer_always = "0"' -e '$pdf_previewer = "zathura -x \"nvr --servername /tmp/nvimQft1R3/0 --remote +\%{line} \%{input}\" \%S"' -e '$success_cmd = "echo vimtex_compiler_callback_success"' -e '$failure_cmd = "echo vimtex_compiler_callback_failure"' 'dlf.tex'
viewer: Zathura
xwin id: 0
process:
pid: -
cmd: zathura -x "nvr --servername /tmp/nvimQft1R3/0 --remote-expr \"vimtex#view#reverse_goto(%{line}, '%{input}')\"" --synctex-forward 3:1:'/home/ashish/documents/reports/semester-4/dlf.tex' '/home/ashish/documents/reports/semester-4/dlf.pdf' >/dev/null 2>&1 &
qf: LaTeX logfile
config:
packages:
default: 1
default: 1
document class:
packages:
adjcalc
adjustbox
amsbsy
amsgen
amsmath
amsopn
amstext
collectbox
epstopdf-base
float
graphics
graphicx
grfext
hyphenat
ifoddpage
iftex
infwarerr
keyval
kvdefinekeys
kvoptions
kvsetkeys
longtable
ltxcmds
natbib
pdftexcmds
revsymb4-1
textcase
trig
trimclip
url
varwidth
xkeyval
First, a couple of comments to your config:
When you use vim-plug, you don't need these lines:
filetype plugin on
syntax on
filetype plugin on
filetype indent on
You don't need set nocompatible in your vimrc file.
You don't need to set vimtex options to their default values, i.e. you can simplify the vimtex options to this:
let g:tex_flavor = "latex"
let g:vimtex_view_method = "zathura"
let g:vimtex_quickfix_open_on_warning = 0
Note, this should all be unrelated to your issue. So, back to topic. I have to admit I simply have no idea what is causing the difference here. Essentially, both latexmk and vim/vimtex will call zathura with similar options. However, with <localleader>ll, the latexmk process (which is a Perl script) will start zathura in the background. Perhaps there is something special that is happening here. You can inspect the output of <localleader>lo after you've started compilation to see the exact command issued by latexmk. But again, I don't understand what would be the essential difference here, as I'm not familiar with this "swallowing" feature.
Perhaps a sort of solution could be to prevent latexmk from opening the viewer at all:
let g:vimtex_view_automatic = 0
This does mean the document is not opened until you do <localleader>lv. But I have to admit I like that myself (and so I use this option).
Thanks for the suggestions on my init.vim. I used to use plain vim earlier and simply ported my .vimrc to neovim.
About the issue, I couldn't pinpoint what latexmk was exactly doing to invoke zathura. I am aware that if any shell script uses setsid -f for spawning a window, that it is not swallowed but am not clear with the behaviour of latexmk. I guess, I'll simply go with your suggestion of using
let g:vimtex_view_automatic = 0
Thanks for the help as always @lervag. I just want to say what a great plugin that vimtex is!
Thanks, happy to hear it :)