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

Let g:vimtex_view_method = 'zathura' , but cannot open zathura after compilation. #2630

Closed
ez4lionky opened this issue Feb 12, 2023 · 18 comments
Labels

Comments

@ez4lionky
Copy link

ez4lionky commented Feb 12, 2023

Description

I set g:vimtex_view_method = 'zathura' in ftplugin/tex/tex.vim. In neovim I execute :echo g:vimtex_view_method, it outputs "zathura". But when I query the VimtexInfo, the value of viewer is still "General". The neovim cannot open the zathura when finishing compilation as well as use shortcut \lv.

image

image

But I can use zathura main.pdf to open the pdf file. ldd $(which zathura) | grep libsynctex also shows the linked .so file.

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Ubuntu 20.04.4 LTS
  Vim version: NVIM v0.8.1
  Has clientserver: true
  Servername: /run/user/1000/nvim.1314874.0

VimTeX project: main
  base: main.tex
  root: /home/lionky/Documents/
  tex: /home/lionky/Documents/main.tex
  main parser: current file verified
  document class: article
  packages: amsbsy amsfonts amsgen amsmath amsopn amssymb amstext amsthm atbegshi auxhook bm booktabs calc color empheq epstopdf-base etexcmds etoolbox everyshi expl3 geometry graphics graphicx iftex ifvtex infwarerr keyval kvdefinekeys kvoptions kvsetkeys lipsum ltxcmds mathtools mdframed mhsetup needspace pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfplots pgfrcs pgfsys psfrag tikz trig xcolor xparse zref-abspage zref-base
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
    job: 
      pid: -
      cmd: xdg-open '/home/lionky/Documents/main.pdf'
  qf method: LaTeX logfile
@ez4lionky ez4lionky added the bug label Feb 12, 2023
@lervag
Copy link
Owner

lervag commented Feb 12, 2023

I set g:vimtex_view_method = 'zathura' in ftplugin/tex/tex.vim.

You need to define VimTeX options earlier than during filetype plugin loading. I.e., put it in your .vimrc, init.vim, init.lua, or in a plugin/vimtex.vim file.

@ez4lionky
Copy link
Author

@lervag
Thanks for your reply!
You're right, I put vim.g.vimtex_view_method='zathura' in plugin/init.lua and it works!

Now I encountered another problem with inverse search by using Zathura.
After I updated the init.lua, now my VimtexInfo becomes:
image

It seems like the inverse search should work according to #2219 and #2281.
I'm sure the Vimtex plugin is installed with ft or opt argument.
But the inverse search just didn't work, do you have any ideas?

Thanks for your time in advance!

@lervag
Copy link
Owner

lervag commented Feb 12, 2023

Can you explain what you are trying when you are trying to do inverse search?

@ez4lionky
Copy link
Author

Well, I first use \v to open a Zathura pdf viewer to check the compiled contents.
The highlight text block is the same as the content around the cursor in neovim.

But when I try to use double-click or ctrl+click to jump into the line of relevant codes in another section.
It failed, and the status bar of Zathura shows the log: Copied selected text to selection clipboard.

@lervag
Copy link
Owner

lervag commented Feb 12, 2023

From the screenshots and report, it seems you have things properly set up. Perhaps you used the wrong sequence to invoke inverse search? Inverse search with Zathura is triggered with CTRL + clik (left mouse button) somewhere in the PDF document.

@ez4lionky
Copy link
Author

Yes, I use CTRL + click (left mouse button), but it still didn't work.
I also tried double-click, but it also cannot work.

I'm wondering if there is any way I can debug the whole process?
Or if you need any extra information, just ask me!

@lervag
Copy link
Owner

lervag commented Feb 12, 2023

Strange. Let's start by simplifying everything. Can you try this:

  • Create a test directory /home/lionky/vimtex-test with two files: test.tex and test.vim with contents as below.
  • Open a terminal, cd to the directory, then do nvim --clean -u test.vim.
  • Now do \ll to compile and possibly \lv to open the viewer.
  • Within the viewer, press <ctrl>+click on "Hello moon".

What happens now?

test.vim:

set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable

let g:vimtex_view_method = 'zathura'

test.tex

\documentclass{minimal}
\begin{document}
Hello World

Hello Moon
\end{document}

@lervag
Copy link
Owner

lervag commented Feb 12, 2023

I would be surprised if things work now, so I'll just hint on the next step, which is to open Zathura from a terminal with the same command as VimTeX uses (you find it with :VimtexInfo). I'll explain further if it becomes relevant.

@ez4lionky
Copy link
Author

ez4lionky commented Feb 12, 2023

I have changed a little about the runtimepath variable, because I use the packer to install the Vimtex:

set nocompatible
set runtimepath^=~/.local/share/lunarvim/site/pack/packer/start/vimtex
set runtimepath+=~/.local/share/lunarvim/site/pack/packer/start/vimtex/after
filetype plugin indent on
syntax enable

let g:vimtex_view_method = 'zathura'

test.tex is the same as you mentioned.

I can compile the tex file and view the compiled content. My cursor is on the first row, i.e. Hello World.
But it still has no effect when using <ctrl>+click, it doesn't jump into the code "Hello Moon".

I also tried to run the same command as VimTeX uses (in :VimtexInfo), but it outputs an error: could not open document.

@ez4lionky
Copy link
Author

ez4lionky commented Feb 12, 2023

Update: I tried the same command in :VimtexInfo again in path ~/vimtex-test but changed the argument --synctex-forward 1:1 to --synctex-forward 5:1, and it worked. The highlight in Zathura focuses on "Hello Moon". But the cursor in nvim still has no effect.

@lervag
Copy link
Owner

lervag commented Feb 12, 2023

I have changed a little about the runtimepath variable, …

Ah, yes, good. I should have mentioned that.

I can compile the tex file and view the compiled content. My cursor is on the first row, i.e. Hello World. But it still has no effect when using <ctrl>+click, it doesn't jump into the code "Hello Moon".

Just to be clear: you are doing <ctrl>+click in Zathura, right? Not in neovim? Inverse search is search performed from the PDF viewer.

I tried the same command in :VimtexInfo again in path ~/vimtex-test but changed the argument "--synctex-forward 1:1" to "--synctex-forward 5:1", and it worked.

Yes, but that is forward search and is irrelevant to the problem you are describing.

What you want to do is this:

  • Open a terminal and cd to the test directory.
  • If necessary, start neovim and compile the document from VimTeX with \ll and quit neovim afterwards.
  • Run this command:
    zathura -x "/usr/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" test.pdf&
  • Zathura should now open and view the test.pdf file.
  • Next: Open a new terminal, go to the same directory and open test.tex with neovim with nvim --clean -u test.vim.
  • What happens if you do <ctrl>+click in Zathura at "Hello moon" now? Is there any output in the first terminal?

@ez4lionky
Copy link
Author

Yes, I'm doing <ctrl>+click in Zathura.

I first compile the document by using \ll and quit, then I run

zathura -x "/usr/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" test.pdf&

Zathura now is open and view the test.pdf file.
Next I use nvim --clean -u test.vim test.tex to open the tex file.

When I do <ctrl>+click in Zathura at "Hello moon", in the terminal launch the Zathura, it says "execv error: No such file or directory".
In the neovim window that opens test.tex it still no jump or any effect.

@lervag
Copy link
Owner

lervag commented Feb 13, 2023

I first compile the document by using \ll and quit, then I run

zathura -x "/usr/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" test.pdf&

When I do <ctrl>+click in Zathura at "Hello moon", in the terminal launch the Zathura, it says "execv error: No such file or directory".

Ok; next step.

  • Similar to before, open test.tex with neovim + VimTeX.

  • Open a new terminal, go to same path, then run this:

    /usr/bin/nvim --headless -c "VimtexInverseSearch 5 '/home/.../test.tex'"

    Use the correct path to the .tex file in the above.

Additionally, could you give me some more info:

  • Which version of Zathura do you use? (zathura --version)
  • What's the output of zcat test.synctex.gz?

@ez4lionky
Copy link
Author

ez4lionky commented Feb 13, 2023

Well, when I use /usr/bin/nvim --headless -c "VimtexInverseSearch 5 '/home/.../test.tex'" it failed and said VimtexInverseSearch is not an editor command!

Now I'm aware that I don't install Vimtex in neovim since I've been using lunarvim all the time.
Vimtex seems like will specify the synctex-editor-command with "/usr/bin/nvim", and use the command "VimtexInverseSearch" to communicate with neovim.

BTW, I have not noticed the subtle relationship between lunarvim and neovim, thus costs several hours to debug.

After installing the Vimtex in the original neovim, now I can inverse search successfully!
Thanks for your time and information to help me out, now I can type latex smoothly.

@lervag
Copy link
Owner

lervag commented Feb 13, 2023

Well, when I use /usr/bin/nvim --headless -c "VimtexInverseSearch 5 '/home/.../test.tex'" it failed and said VimtexInverseSearch is not a editor command!

Ok; this implies that VimTeX was not installed properly. A lot of people force lazy loading of plugins, and that may be the problem here. Perhaps LunarVim lazily loads VimTeX. That would explain the problem. VimTeX is already lazily loaded by the builtin mechanisms in Vim, but VimTeX needs to create the VimtexInverseSearch command globally and not lazily. The init cost is neglibable.

BTW, I have not noticed the subtle relationship between lunarvim and neovim, thus costs several hours to debug.

And this is why I tend to suggest that people use their own configurations and that they avoid too many plugins. Still, I think projects like LunarVim should often be safe, so I'm surprised this was an issue! I'll check and possibly report upstream.

After installing the Vimtex in the original neovim, now I can inverse search successfully! Thanks for your time and information to help me out, now I can type latex smoothly.

Glad to hear it! Enjoy :)

@lervag lervag closed this as completed Feb 13, 2023
@lervag
Copy link
Owner

lervag commented Feb 13, 2023

Ok, I didn't see any errors on the LunarVim project in this regard, so I think the error must have been on your side. I believe you may have installed VimTeX lazily without knowing that it is not good. :)

@ez4lionky
Copy link
Author

Yes, I'm new to vim and lua configuration. :)

It becomes complex when there are too many plugins and configurations, especially when some minor configurations really matter.

Anyway, thanks for your patience and help again!

@lervag
Copy link
Owner

lervag commented Feb 13, 2023

No problem; glad to help.

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

No branches or pull requests

2 participants