VSCode Texlive / LatexWorkshop - 无法构建或预览 Latex 文件(无法理解对同一问题的先前回答)

VSCode Texlive / LatexWorkshop - 无法构建或预览 Latex 文件(无法理解对同一问题的先前回答)

更新-找到解决方案

感谢 Alan,我得以解决这个问题。我的两个问题是。

  1. 我不知道如何在 VSCode 上的 LaTeX Workshop 中设置正确的路径
  2. 我没有正确地运行 perl 安装命令tex-live 安装页面

当您到达本页的 perl 脚本部分时,请注意安装过程中遇到困难的任何人。下载必要的依赖项至少需要 20 分钟 - 40 分钟。我以为我做错了什么,但最终一切都正常了!

非常感谢艾伦的帮助。

原始问题

我是这个网站的新用户,虽然我读过类似的帖子,但我仍然不清楚这个过程。如果您能先阅读帖子,再做判断,我将不胜感激。

我读本文导致我得到不成功的结果。其中有一些线索,但并不十分清楚。

我是 Ubuntu 新手,正在尝试理解许多新流程......我想在 VSCodes LaTeX Workshop 中查看 .tex 文件。

我能够看到我有 40 个与 latexmk 关联的包,这些包是我通过 找到的apt-file search latexmk

usr/share/texlive 存在,并且有 174530 个与之关联的包。我已将 LaTeX Workshop 下载到我的 VSCode 实例上。

由于包太多,我不确定哪些可执行文件需要显示在路径中,尽管我知道如何更新路径。我还知道 LaTeX Workshop 设置配置中有路径。其中大部分我可以使用 usr/bin/latexmk 或类似命令进行设置。

Build LaTeX Project我真的不知道我错过了什么。我附上了尝试运行/时出现的错误的日志

[15:33:39.209][Extension] $SHELL: /bin/bash
[15:33:39.210][Extension] $LANG: C.UTF-8
[15:33:39.210][Extension] $LC_ALL: undefined
[15:33:39.210][Extension] process.platform: linux
[15:33:39.210][Extension] process.arch: x64
[15:33:39.210][Extension] vscode.env.appName: Visual Studio Code
[15:33:39.210][Extension] vscode.env.remoteName: wsl
[15:33:39.210][Extension] vscode.env.uiKind: 1
[15:33:39.211][Extension] LaTeX Workshop initialized.
[15:33:39.214][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[15:33:39.217][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[15:33:39.220][Manager] Current workspace folders: ["file://%WS1%"]
[15:33:39.221][Manager] Found root file from active editor: %WS1%/demo_1.tex
[15:33:39.222][Manager] Root file changed: from undefined to %WS1%/demo_1.tex
[15:33:39.222][Manager] Start to find all dependencies.
[15:33:39.222][Manager] Root file languageId: latex
[15:33:39.223][Event] ROOT_FILE_CHANGED: "%WS1%/demo_1.tex"
[15:33:39.223][Cacher][Watcher] Reset.
[15:33:39.228][Cacher] Adding %WS1%/demo_1.tex .
[15:33:39.228][Cacher][Watcher] Watched %WS1%/demo_1.tex with a new watcher on %WS1% .
[15:33:39.229][Event] FILE_WATCHED: "%WS1%/demo_1.tex"
[15:33:39.231][Cacher] Caching %WS1%/demo_1.tex .
[15:33:39.232][Cacher] Updated inputs of %WS1%/demo_1.tex .
[15:33:39.232][Cacher] Parse LaTeX AST: %WS1%/demo_1.tex .
[15:33:39.232][Event] ROOT_FILE_SEARCHED
[15:33:39.236][Server] valdOrigin is http://127.0.0.1:40903
[15:33:39.245][Cacher] Parsed LaTeX AST: %WS1%/demo_1.tex .
[15:33:39.245][Cacher][Path] Calling usr/bin/kpsewhich to resolve article.cls .
[15:33:39.252][Cacher] Updated elements in 6.96 ms: %WS1%/demo_1.tex .
[15:33:39.252][Event] FILE_PARSED: "%WS1%/demo_1.tex"
[15:33:39.255][Cacher][Path] Non-existent .fls for %WS1%/demo_1.tex .
[15:33:39.256][Structure] Structure force updated with 0 root sections for %WS1%/demo_1.tex .
[15:33:39.256][Event] STRUCTURE_UPDATED
[15:33:44.449][Commander] BUILD command invoked.
[15:33:44.449][Commander] The document of the active editor: file://%WS1%/demo_1.tex
[15:33:44.449][Commander] The languageId of the document: latex
[15:33:44.449][Manager] Current workspace folders: ["file://%WS1%"]
[15:33:44.450][Manager] Found root file from active editor: %WS1%/demo_1.tex
[15:33:44.450][Manager] Keep using the same root file: %WS1%/demo_1.tex
[15:33:44.450][Structure] Structure updated with 0 root sections for %WS1%/demo_1.tex .
[15:33:44.450][Event] ROOT_FILE_SEARCHED
[15:33:44.451][Event] STRUCTURE_UPDATED
[15:33:44.451][Commander] Building root file: %WS1%/demo_1.tex
[15:33:44.451][Builder] Build root file %WS1%/demo_1.tex
[15:33:44.455][Builder] outDir: %WS1% .
[15:33:44.458][Builder] Preparing to run recipe: latexmk.
[15:33:44.458][Builder] Prepared 1 tools.
[15:33:44.463][Builder] Recipe step 1 The command is latexmk:["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%WS1%","%WS1%/demo_1"].
[15:33:44.463][Builder] env: {}
[15:33:44.464][Builder] root: %WS1%/demo_1.tex
[15:33:44.464][Builder] cwd: %WS1%
[15:33:44.739][Builder] LaTeX build process spawned with PID undefined.
[15:33:44.740][Builder] LaTeX fatal error on PID undefined. Error: spawn latexmk ENOENT
[15:33:44.740]Error: spawn latexmk ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

答案1

您需要在设置中将 PATH 添加到 LaTeX 工具的“env”:键中。

去做这个:

Command-Shift-P -> 偏好设置打开用户设置 (JSON)

搜索latex-workshop.latex.tools

这个对象数组里面是每个构建工具。首次安装时,它们看起来(大致)像这样:

{
        "name": "latexmk",
        "command": "latexmk",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-pdf",
            "-outdir=%OUTDIR%",
            "%DOC%"
        ],
        "env": {}
            
    },

您可以看到有一个空"env":属性。这是您需要为所有工具更改的内容。因此,"env": {}您应该将其替换为以下内容。您首先需要知道安装后 TeX Live 二进制文件的路径。为此,您可以在命令行中输入:

which pdflatex

这将返回 的完整路径pdflatex。在我的 Mac 机器上,它返回:

/Library/TeX/texbin/pdflatex

因此我将以下内容添加到"env":属性中:

"env": {"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:"}

对于像您这样的 Linux 发行版,路径会有所不同,可能类似于:

 /usr/local/texlive/2023/bin/x86_64-linux/

这就是您应该在"env":属性中使用的内容:

"env": {"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/texlive/2023/bin/x86_64-linux/:"}

您应该为数组中的所有对象添加此项tools(包括arara没有属性"env":但应该有的工具)。

您不需要对recipes数组进行任何操作。

保存设置文件,一切就会按您预期的方式工作。

相关内容