-
Notifications
You must be signed in to change notification settings - Fork 395
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
VimTeX in WSL1,when call the SumtraPDF to preview, it loads the wrong PDF Path #2566
Comments
I have a similar setup as yours. I do not encounter this error. (I use VIM and not neovim though). Infact, I do not have any pdf viewer setting in my .vimrc at all. Have you tried setting Sumatra PDF as the default application to open pdf files in native Windows? I know that Acrobat PDF does not work well with VimTeX and the latter tends to be the default application to open pdf files in Windows. |
thanks for your reply, sumatraPDF is always the default pdf viewer in Windows. But the problem is still there |
Hmm... I am not a great trouble shooter in this regard. WSL1 is rather old. Is updating to WSL2 a possibility? https://learn.microsoft.com/en-us/windows/wsl/compare-versions Can you open a pdf file from within WSL by the following command?
Does this open up main.pdf using SumatraPDF and other variants of this command from different directories and providing relative addressing? This command works at my end as I described and if it doesn't at your end that may be a guide to troubleshoot. |
WSL1 is rather old. Is updating to WSL2 a possibility?
Another thing is, if the project is created in WSL1 it self (stored in WSL1 space), it also works fine |
I would suggest the following changes to your options (similar to what is suggested in the docs at vim.g.vimtex_view_general_viewer = 'SumatraPDF.exe'
vim.g.vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf' To configure inverse search, you should instead configure from within SumatraPDF (again, as described in the docs).
Can you show a screenshot of the error message?
The path is not wrong. If you are in WSL, then the full absolute path is
|
I don't think that's a very good reason, except for very specific purposes. LaTeX is not one of them, I believe. At least, I've not heard anyone complain about performance related issues using LaTeX and VimTeX in WSL2. |
Hmm. That's interesting and seems like a hard problem. The problem here is that you are using neovim inside a Bash shell in WSL, in which case VimTeX "believes" it is on Linux and behaves accordingly. This is usually fine, but in this specific case we are passing a file argument to SumatraPDF, which is a Windows applications, and thus the absolute path is not recognized because we are also crossing the WSL boundary. I've not encountered this before, so before looking into any specific solution, I'm curious if this may be already resolved on WSL2 in the underlying interface between WSL and Windows. @TryerGit: Do you have WSL2 and SumatraPDF both available; if so, would you be willing to try and duplicate this issue? It should be quite easy:
|
Is it possible do some tricks in vimtex. For examle I could open the pdf right in shell with the then I could create a function in bash, actually in zsh
After that I could use But If I tried to set
But I still believe there is some trick to overcome my problem |
I got some interesting results:
This is the folder where in Windows (via WSL) Typing returns Typing as if in Linux : Typing opens up SumatraPDF app with no file loaded.
I get: I further tried: This gives error: Then, I navigated to E:\GoogleDrive\CVs\ in Windows and opened up WSL here. This gives me:
Now issuing opens up SumatraPDF and properly displays Then, I wanted to test if this across folder problem persists in native windows. It did not. For e.g., I issued
This works just fine and the So, it seems that the "problem" is not because of which version of is being used -- WSL1 or WSL2, nor does the problem seem to be in VimTeX. It seems that WSL opening of native Windows files cannot happen across folders or else it cannot work with absolute paths. It only works if the file resides in the current folder or possibly with relative addressing. I am not sure about @Liampor 's workflow. The above tests are news to me as well and somewhat unexpected -- I expected WSL to be able to handle opening files fine across folders -- but my workflow with SumatraPDF has been working fine thus far (knock on all wood) since I have ETA: What finally worked was the following:
This may hold the clue -- i.e., the path to be specified via WSL to a Windows file should following Windows naming convention. The above opened up SumatraPDF and the pdf file just fine. Below also works:
|
Ah, yes, I believe this is the most elegant and simple solution. I.e., not to change anything in VimTeX, but instead to make a simple wrapper script. It should be a script, not a function. E.g., ensure you have e.g. #!/usr/bin/env bash
sumatrapdf.exe $(wslpath -m $1) Notice, though, it must be slightly more complicated. I can help, but I don't have the time right now. The point is, you need to only wrap the path, not the other arguments. Also, thanks for the input, @TryerGit! I believe @Liampor already found a proper way to solve this with the |
@Liampor Notice that with the earlier proposed settings (except changing the viewer command), VimTeX will execute the following command: SumatraPDF.exe -reuse-instance -forward-search '/mnt/d/Project/main.tex' 1 '/mnt/d/Project/main.pdf' So, the wrapper script must recognize the paths (both of them, probably), and wrap these with |
Yes, this looks quite good. It doesn't need to be perfect as long as it works.
That's strange. It is unclear where this error appears. Inside SumatraPDF? If so, then I believe the best way to debug is to test various forms of the command used in the command line. For instance, in a WSL terminal, try to run these commands: SumatraPDF.exe -reuse-instance -forward-search '/mnt/d/Project/main.tex' 1 'D:\Project\main.pdf'
SumatraPDF.exe -reuse-instance -forward-search 'D:\Project\main.tex' 1 'D:\Project\main.pdf' Do you see the error in both of these? |
Hi @lervag
change to Issue may be related: sumatrapdfreader/sumatrapdf#377 |
The issue you link is related, but I'm not sure if it is exactly the same. I believe the problem is related to the inherent conflict that you are using a Windows application as PDF reader with a document compiled with synctex in a Linux environment. The synctex file uses a syntax that includes the source file path, and SumatraPDF probably does not "understand" the unix type paths. Or something like that. You can check this by examining the |
Hi @lervag I have opened the
and then replace it with
then give command line
It works ! Now the question would be, how to control the |
First, I'm glad to hear you tested this and can verify it works. It means I understood things correctly (I wasn't quite sure). I think it would be possible to overcome the problem by making the wrapper script more advanced. It would require some semi-advanced scripting, e.g. a flow like In fact, this story could potentially be a helpful addition to the faq section (e.g. "How can I use VimTeX with SumatraPDF in Vim/Neovim in Windows WSL?"), at least if you happen to find something that works well. |
Hi @lervag. After some searchs I finally get it to work now. I have found a command in forum: find -maxdepth 1 -name "*.synctex.gz" -execdir \
bash -c 'cat "{}" | gunzip | sed --expression="s@/mnt/\(.\)/@\1:/@g" | gzip > "{}.tmp" && mv "{}.tmp" "{}"' \; Explanation:
My script is now like: #!/bin/zsh
# This script is used to let the SumatraPDF open the pdf after path conversion
new_arg=() # ceate arguments array
declare -i idxMntOccur=0
for arg ($@) {
if [[ "$arg" == /mnt* ]] {
# convert to windows style path
idxMntOccur=idxMntOccur+1
winPath=$(wslpath -m $arg)
new_arg+=$winPath
if (($idxMntOccur == 1)) {
# convert the path in .syntex to windows style
# run only "/mnt/d" like path is detected
find ${PWD} -maxdepth 1 -name "*.synctex.gz" -execdir \
bash -c 'cat "{}" | gunzip | sed --expression="s@/mnt/\(.\)/@\1:/@g" | gzip > "{}.tmp" && mv "{}.tmp" "{}"' \;
}
} else {
new_arg+=$arg
}
}
$(sumatrapdf.exe $new_arg) |
Very cool! I took the liberty of slightly cleaning up your post, and I will write a short faq entry with a link to it. If that is OK with you, that is? In case you should adjust or improve this further, please feel free to update your comment and/or continue the thread. |
Of course, just take it without any restrictions. What I have done is just under your suggestions. |
Description
Using Windows 10 WSL1 + NeoVim + VimTeX.
LaTeX project is located in
D:\Project
SumatraPDF is the default PDF viewer in Windows
Access the project in WSL1 via
cd /mnt/d/Project
then call nvim. After successfully compiling the sumatraPDF shows error while loading the PDF file:D:/mnt/d/Project/main.pdf
From my understanding, the path is wrong, there shouldn't be
/mnt/d
thereSteps to reproduce
D:\Project
cd /mnt/d/Project
, then enter neovim vianvim
D:/mnt/d/Project/main.pdf
Related Settings:
Expected behavior
After the compiling,sumatraPDF should be automatically called and loading the generated PDF
Actual behavior
SumtraPDF cannot load the generated PDF error, shows the error, "loading file:
D:/mnt/d/Project/main.pdf
", the path is wrong, it shouldn't contain "/mnt/d"Do you use a latexmkrc file?
No
VimtexInfo
The text was updated successfully, but these errors were encountered: