James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.64k stars 532 forks source link

Cannot find TeX Live PATH #4070

Closed Firestar-Reimu closed 10 months ago

Firestar-Reimu commented 10 months ago

I installed texlive at ~/.texlive as home user (not root)

and I added PATH to my .bashrc (I use bash)

echo $PATH
/home/Firestar/.miniconda/bin:/home/Firestar/.miniconda/condabin:/home/Firestar/.texlive/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

but the latex-workshop cannot find latexmk (while my bash can find it)

Does the executable exist? $PATH: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl, $Path: undefined, $SHELL: /usr/bin/bash

my setting is:

"latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-lualatex",
                "-bibtex",
                "-synctex=1",
                "--shell-escape",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "clean",
            "command": "latexmk",
            "args": [
                "-c",
                "%DOCFILE%"
            ]
        }
    ],
    "latex-workshop.latex.recipes": [
        {
            "name": "latexmk",
            "tools": [
                "latexmk"
            ]
        },
        {
            "name": "clean",
            "tools": [
                "clean"
            ]
        }
    ],
Firestar-Reimu commented 10 months ago

Full extension log

[11:09:57.448][Commander] BUILD command invoked.
[11:09:57.449][Commander] The document of the active editor: file:///home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.450][Commander] The languageId of the document: latex
[11:09:57.450][Manager] Current workspace folders: undefined
[11:09:57.452][Manager] Found root file from active editor: /home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.452][Manager] Keep using the same root file: /home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.453][Event] ROOT_FILE_SEARCHED
[11:09:57.454][Event] STRUCTURE_UPDATED
[11:09:57.455][Commander] Building root file: /home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.455][Builder] Build root file /home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.464][Builder] outDir: /home/Firestar/D/实测天体物理1/作业/计算作业 .
[11:09:57.468][Builder] Preparing to run recipe: latexmk.
[11:09:57.469][Builder] Prepared 1 tools.
[11:09:57.475][Builder] Recipe step 1 The command is latexmk:["-lualatex","-bibtex","-synctex=1","--shell-escape","-interaction=nonstopmode","-file-line-error","Homework"].
[11:09:57.476][Builder] env: undefined
[11:09:57.477][Builder] root: /home/Firestar/D/实测天体物理1/作业/计算作业/Homework.tex
[11:09:57.478][Builder] cwd: /home/Firestar/D/实测天体物理1/作业/计算作业
[11:09:57.492][Builder] LaTeX build process spawned with PID undefined.
[11:09:57.496][Builder] LaTeX fatal error on PID undefined. Error: spawn latexmk ENOENT
[11:09:57.497]Error: spawn latexmk ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
[11:09:57.498][Builder] Does the executable exist? $PATH: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl, $Path: undefined, $SHELL: /usr/bin/bash
[11:09:57.498][Builder] 
Firestar-Reimu commented 10 months ago

I added the output (mypath) of echo $PATH to /etc/environment:

PATH=(mypath):$PATH

and the problem is solved.

But I still want to know why vscode do not recognize my .bashrc

jlelong commented 10 months ago

The file .bashrc is only read by interactive bash shells (bash terminal in short). A GUI app not started from a terminal is not aware of anything defined in .bashrc. On Ubuntu, use ~/.pam_environment or its system-wide equivalent /etc/environment to set an environment variable for all programs regardless of how they are started.

See from https://help.ubuntu.com/community/EnvironmentVariables#A.2BAH4-.2F.pam_environment

Shell config files such as ~/.bashrc, ~/.bash_profile, and ~/.bash_login are often suggested for setting environment variables. While this may work on Bash shells for programs started from the shell, variables set in those files are not available by default to programs started from the graphical environment in a desktop session.

Firestar-Reimu commented 10 months ago

I use Arch Linux, but thank you for your advice.