VSCode on MacとLaTeX Workshopでenv: perl: no such file or directory

症状

事前にHomebrewでVSCodeとMacTeX(とPerl)をインストールしていた

VSCode拡張機能LaTex Workshopをインストールして、適当な.texファイルを用意してcommand + option + Bでコンパイルしようとしたが以下のようなエラー

拡張機能のログを見てもこんな感じ

[01:32:43][Commander] BUILD command invoked.
[01:32:43][Commander] The document of the active editor: file://%WS1%/test.tex
[01:32:43][Commander] The languageId of the document: latex
[01:32:43][Manager] Current workspace folders: ["file://%WS1%"]
[01:32:43][Manager] Found root file from active editor: %WS1%/test.tex
[01:32:43][Manager] Keep using the same root file: %WS1%/test.tex
[01:32:43][Structure] Structure updated with 1 root sections for %WS1%/test.tex .
[01:32:43][Commander] Building root file: %WS1%/test.tex
[01:32:43][Builder] Build root file %WS1%/test.tex
[01:32:43][Builder] outDir: %WS1% .
[01:32:43][Builder] Preparing to run recipe: latexmk.
[01:32:43][Builder] Prepared 1 tools.
[01:32:43][Builder] Recipe step 1 The command is latexmk:[].
[01:32:43][Builder] env: {"PATH":"/Library/TeX/texbin"}
[01:32:43][Builder] root: %WS1%/test.tex
[01:32:43][Builder] cwd: %WS1%
[01:32:43][Builder] LaTeX build process spawned with PID 50552.
[01:32:43][Builder] Recipe returns with error code 127/null on PID 50552.
[01:32:43][Builder] Does the executable exist? $PATH: /Library/TeX/texbin, $Path: undefined, $SHELL: /bin/zsh
[01:32:43][Builder] env: perl: No such file or directory

[01:32:43][Builder] Cleaning auxiliary files and retrying build after toolchain error.
[01:32:43][Cleaner] Clean glob matched files {"globs":["*.aux","*.bbl","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gls","*.fls","*.log","*.fdb_latexmk","*.snm","*.synctex(busy)","*.synctex.gz(busy)","*.nav","*.vrb"],"outdir":"%WS1%"} .
[01:32:43][Cleaner] Ignore folder glob patterns with globstar:  .
[01:32:43][Builder] Recipe step 1 The command is latexmk:[].
[01:32:43][Builder] env: {"PATH":"/Library/TeX/texbin"}
[01:32:43][Builder] root: %WS1%/test.tex
[01:32:43][Builder] cwd: %WS1%
[01:32:43][Builder] LaTeX build process spawned with PID 50553.
[01:32:43][Builder] Recipe returns with error code 127/null on PID 50553.
[01:32:43][Builder] Does the executable exist? $PATH: /Library/TeX/texbin, $Path: undefined, $SHELL: /bin/zsh
[01:32:43][Builder] env: perl: No such file or directory

ちなみにターミナルからはlatexmkで普通にコンパイルできる

解決した方法

setting.jsonを見直してみる。

Before

//省略
"latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [],
            "env": {
                "PATH": "/Library/TeX/texbin"
            }
        },
//省略

PATHperlのパスを加えてみる(自分はHomebrewでインストールしていたので/opt/homebrew/bin)。

After

//省略
"latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [],
            "env": {
                "PATH": "/Library/TeX/texbin:/opt/homebrew/bin"
            }
        },
//省略

これでうまくいった。

参考

https://github.com/James-Yu/LaTeX-Workshop/issues/2390