Hannah-Sten / TeXiFy-IDEA

LaTeX support for the IntelliJ platform by JetBrains.
https://hannah-sten.github.io/TeXiFy-IDEA
MIT License
893 stars 89 forks source link

Incorrect --output-directory path generation when compiling via WSL2 #1955

Closed Nicceboy closed 3 years ago

Nicceboy commented 3 years ago

Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

PyCharm 2021.1.2 (Professional Edition) Build #PY-211.7442.45, built on June 1, 2021

Operating System

Windows 10.0.21390

TeXiFy IDEA version

0.7.7

What I did (steps to reproduce)

Since the latest version, I cannot build any projects. (Can be also related to latest PyCharm version) When attempting to build the project, space in the generated output directory path is not handled/escaped properly. The path also contains portion of path which probably should not be in there.

Default LaTeX run configuration has been used. Only main tex file has been selected.

Minimal example to reproduce the problem

Latex content does not matter. PyCharm must be installed to directory with spaces and used with WSL2. This happens similarly on different compilers.

Expected behavior

When compiling the project, generated command should have --output-directory correctly encoded/escaped to note spaces and it should match the one configured on LaTeX configuration options.

Actual behavior

Odd output directory has been generated. I am unsure if the path of PyCharm binary folder even belongs here (it does not appear in the previous versions and probably changes/breaks desired path), but compile process itself breaks because spaces are not noted.

Example of generated directory: "-output-directory=/windir/c/Program Files/JetBrains/PyCharm 2021.1.1/jbr/bin/'/wsl$/Arch/home/user/out'\"

I did downgrade to 0.7.5 and it works well. It does not have portion of including the PyCharm binary folder into the path, so maybe problem lies because it should not exist in the first case.

(if applicable) The full stacktrace of the exception thrown

bash -ic "pdflatex -file-line-error -interaction=nonstopmode -synctex=1 -output-format=pdf \"-output-directory=/windir/c/Program Files/JetBrains/PyCharm 2021.1.1/jbr/bin/'/wsl$/Arch/home/user/out'\" /windir/c/Program Files/JetBrains/PyCharm 2021.1.1/jbr/bin/'/wsl$/Arch/home/user/main.tex'"
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
! I can't find file `/windir/c/Program'.
<*> /windir/c/Program 
                      Files/JetBrains/PyCharm 2021.1.1/jbr/bin//wsl$/Arch/ho...

(Press Enter to retry, or Control-D to exit)
Please type another input file name
! I can't write on file `texput.log'.
(Press Enter to retry, or Control-D to exit; default file extension is `.log')
Please type another transcript file name
! Emergency stop
!  ==> Fatal error occurred, no output PDF file produced!

Process finished with exit code 1
PHPirates commented 3 years ago

\"-output-directory=/windir/c/Program Files/JetBrains/PyCharm 2021.1.1/jbr/bin/'/wsl$/Arch/home/user/out'\"

This is indeed a very odd output path. Escaping spaces works on Linux, so I'll have to see if I can reproduce the issue on Windows. Does it work if you specify a correct output path manually? With or without spaces.

In case you have doubt, of course it shouldn't take bin/ as output path, but that's a bug I've already tried to solve countless times. I hope it won't reappear with the new run configuration we're working on.

Nicceboy commented 3 years ago

In case you have doubt, of course it shouldn't take bin/ as output path, but that's a bug I've already tried to solve countless times. I hope it won't reappear with the new run configuration we're working on.

Maybe this is the issue then, it seems that I can't get rid of it, regardless of what path I select.

PHPirates commented 3 years ago

@Nicceboy What LaTeX distribution are you using, how did you install it and how are you using it?

I tried to follow https://github.com/Hannah-Sten/TeXiFy-IDEA/wiki/WSL-support again which worked for me before, but now I'm using WSL2, and it's not working: bash -ic "pdflatex --version" says command not found.

Can you call pdflatex from the windows command prompt (outside WSL)?

I'm not sure how it works when PyCharm is installed inside WSL, it doesn't sound easy to do. Isn't it then from the perspective of TeXiFy just like you're on Linux? But then you shouldn't have anything to do with wsl-like paths in your run config. It is apparently not the case that it's 'just like Linux', since TeXiFy does seem to be trying to use wsl-like paths, which it only does when running on Windows (checked via System.getProperty("os.name")).

Do you have 'wsl-texlive' selected in your run configuration?

I still can't make sense of the output directory you get though. Here is what TeXiFy does, when you install PyCharm on Windows and then use TeX Live from WSL (which is apparently not exactly your situation):

Please explain what you expect TeXiFy to do exactly, because you give an output path but I don't know what you gave as input and what the intended result is.

You seem to have a very rare setup, so if you want me to help you further, you need to provide more complete details, I can't keep guessing.

Nicceboy commented 3 years ago

I have indeed quite rare setup I believe. I can supply more precise information later, when I have more time. So far, couple notes:

I'am using Arch Linux on WSL2. And texlive-core has been installed. More precisely:

texlive-bibtexextra 2020.56991-1
texlive-core 2020.57066-2
texlive-fontsextra 2020.57042-1
texlive-formatsextra 2020.56699-1
texlive-games 2020.56833-1
texlive-humanities 2020.57034-1
texlive-latexextra 2020.57067-1
texlive-music 2020.56473-1
texlive-pictures 2020.57065-1
texlive-pstricks 2020.56758-1
texlive-publishers 2020.57058-1
texlive-science 2020.57068-1

However, I believe distro is not related to this problem. It is something on PyCharm and how it handles the WSL directories.

I tried to follow https://github.com/Hannah-Sten/TeXiFy-IDEA/wiki/WSL-support again which worked for me before, but now I'm using WSL2, and it's not working: bash -ic "pdflatex --version" says command not found.

It sounds like that pdflatex is not in your Linux distro's path. Can you check it manually? If you list wls distros on PowerShell, it should give following output:

wsl -l
Windows Subsystem for Linux Distributions:
Arch (Default)

In my case, Arch Linux is default. Then, if you run command wsl in PowerShell, it opens default distro. If you run pdflatex in there, it says command not found? If that is the case, command is not in $PATH or it is not installed.

Can you call pdflatex from the windows command prompt (outside WSL)?

I have everything required for compiling installed in Arch Linux on WSL2 , so no.

I'm not sure how it works when PyCharm is installed inside WSL, it doesn't sound easy to do. Isn't it then from the perspective of TeXiFy just like you're on Linux? But then you shouldn't have anything to do with wsl-like paths in your run config. It is apparently not the case that it's 'just like Linux', since TeXiFy does seem to be trying to use wsl-like paths, which it only does when running on Windows (checked via System.getProperty("os.name")).

PyCharm is installed into Windows side, it just uses binaries and directories/files from WSL side. This is quite new feature actually to be so versaile. But it works on previous releases, so something has changed.

Please explain what you expect TeXiFy to do exactly, because you give an output path but I don't know what you gave as input and what the intended result is.

I have only used default run configurations, provided by LaTeX. I select pdfLaTeX compiler (which is default), then the main tex file and finally output directory, which is out subdirectory in current project path. I expect that it compiles pdf file with default settings.

LaTeX distribution is selected to be TeX Live using WSL.

Can you point me to the code pieces/give hint, where these are handled (parameters for command generation), if I take a look as well?

PHPirates commented 3 years ago

Thanks for the information! I was indeed using the wrong default distribution.

I think I found the bug though: we were using wsl wslpath -a 'C:/windows/path' instead of wsl wslpath -a C:/windows/path and it meant that the resulting path was prefixed by the PyCharm installation path. No clue why, though, as I think this means paths with spaces won't work? But I didn't test it. Fixed: https://github.com/Hannah-Sten/TeXiFy-IDEA/blob/bc40fb88ec224b4ceb094df82df56dad5347ab94/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt#L227

Please check if this works for you: TeXiFy-IDEA-0.7.7-saari.zip

PyCharm is installed into Windows side, it just uses binaries and directories/files from WSL side.

Following https://blog.jetbrains.com/pycharm/2021/03/pycharm-2021-1-eap-4/ I tried to open a path \\wsl$\Ubuntu\ but PyCharm couldn't find it.

Nicceboy commented 3 years ago

It seems to be working now, thanks!

Following https://blog.jetbrains.com/pycharm/2021/03/pycharm-2021-1-eap-4/ I tried to open a path \wsl$\Ubuntu\ but PyCharm couldn't find it.

Seems like you can't open the root (\\wsl$\Ubuntu\), I can't open root either. What if you select some subdirectory?

For example, when you click File -> Open , root directory should be visible and expandable:

Screenshot 2021-06-12 174138

PHPirates commented 3 years ago

Right, it indeed works nicely, thanks!