You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu环境下VSCode LaTeX Workshop报错Cannot find LaTeX root file的解决求助

Ubuntu环境下VSCode LaTeX Workshop报错Cannot find LaTeX root file的解决求助

大家好,我最近刚从Windows转到Ubuntu系统,主要是为了学习编程。之前在Windows上用VSCode搭配LaTeX Workshop写LaTeX课程作业一直很顺利,但换到Ubuntu后配置过程中遇到了一堆问题,大部分都磕磕绊绊解决了,唯独最后这个问题卡了好久,实在没办法来求助各位。

问题现象

当我尝试编译LaTeX项目时,终端输出如下内容,之后就没有任何反应了:

[19:17:56.309][Commander] BUILD command invoked.

[19:17:56.310][Commander] The document of the active editor: file://%WS1%/main

[19:17:56.310][Commander] The languageId of the document: latex

[19:17:56.310][Manager] Current workspace folders: ["file://%WS1%"]

[19:17:56.311][Manager] Found root file from active editor: %WS1%/main

[19:17:56.311][Manager] Keep using the same root file: %WS1%/main

[19:17:56.312][Event] ROOT_FILE_SEARCHED

[19:17:56.312][Commander] Cannot find LaTeX root file. See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#the-root-file

[19:17:58.322][Cacher] Error loading cache: %WS1%/main . Forcing.

[19:17:58.328][Structure][LaTeX] Error loading content during structuring: %WS1%/main .

[19:17:58.330][Structure] Structure updated with 0 root sections for %WS1%/main .

[19:17:58.333][Event] STRUCTURE_UPDATED

另外,打开VSCode时的日志里也有相关错误:

[19:17:31.034][Logger] New log placeholder %WS1% registered for /home/alejandro/Documentos/latex/tfm .

[19:17:31.034][Config] latex-workshop.latex.tools: a-lot-of-things-that-flagged-the-question-as-spam

[19:17:31.044][Config] latex-workshop.latex.outDir: "%DIR%/build" .

[19:17:31.085][Manager] Set $LATEXWORKSHOP_DOCKER_LATEX: ""

[19:17:31.093][Server] Creating LaTeX Workshop http and websocket server.

[19:17:31.142][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":41019} .

[19:17:31.164][Extension] Initializing LaTeX Workshop.

[19:17:31.164][Extension] Extension root: /home/alejandro/.vscode/extensions/james-yu.latex-workshop-9.15.0

[19:17:31.164][Extension] $PATH: /home/alejandro/anaconda3/envs/latex/bin:/home/alejandro/anaconda3/condabin:/usr/local/texlive/2023/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

[19:17:31.165][Extension] $SHELL: /bin/bash

[19:17:31.165][Extension] $LANG: en_US.UTF-8

[19:17:31.165][Extension] $LC_ALL: undefined

[19:17:31.165][Extension] process.platform: linux

[19:17:31.165][Extension] process.arch: x64

[19:17:31.165][Extension] vscode.env.appName: Visual Studio Code

[19:17:31.166][Extension] vscode.env.remoteName: undefined

[19:17:31.166][Extension] vscode.env.uiKind: 1

[19:17:31.166][Extension] LaTeX Workshop initialized.

[19:17:31.173][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}

[19:17:31.174][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]

[19:17:31.176][Manager] Current workspace folders: ["file://%WS1%"]

[19:17:31.176][Manager] Found root file from active editor: %WS1%/main

[19:17:31.177][Manager] Root file changed: from undefined to %WS1%/main

[19:17:31.177][Manager] Start to find all dependencies.

[19:17:31.177][Manager] Root file languageId: undefined

[19:17:31.177][Event] ROOT_FILE_CHANGED: "%WS1%/main"

[19:17:31.178][Cacher][Watcher] Reset.

[19:17:31.183][Cacher] Adding %WS1%/main .

[19:17:31.185][Cacher][Watcher] Watched %WS1%/main with a new watcher on %WS1% .

[19:17:31.185][Event] FILE_WATCHED: "%WS1%/main"

[19:17:31.186][Event] ROOT_FILE_SEARCHED

[19:17:31.187][Cacher][Path] Non-existent .fls for %WS1%/main .

[19:17:31.298][Server] valdOrigin is http://127.0.0.1:41019

[19:17:35.047][Cacher] Error loading cache: %WS1%/main . Forcing.

[19:17:35.055][Structure][LaTeX] Error loading content during structuring: %WS1%/main .

我已经尝试过的解决步骤

  • 按照TeXLive官方文档进行快速安装,在home目录创建了texlive文件夹,执行文档中的命令时,cd install-tl-*命令失败,后来用完整的目录名称才完成这一步
  • 尝试更新PATH环境变量,一开始没成功:
    • 参考了其他遇到相同问题的用户方案,试过用tlmgr GUI更新PATH,但执行echo $PATH后还是看不到texlive的路径
    • 按照Ubuntu官方文档关于环境变量的说明,在/etc/profile.d/目录下创建了myenvsvars.sh文件,写入export PATH=$PATH:/usr/local/texlive/2023/bin/x86_64-linux,终于在echo $PATH里看到了texlive的路径,当前PATH内容为:
      /home/alejandro/anaconda3/envs/latex/bin:/home/alejandro/anaconda3/condabin:/usr/local/texlive/2023/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
      
  • 通过sudo apt install latexmk命令安装了latexmk
  • 遇到当前报错后,还尝试给LaTeX Workshop的tools配置手动添加PATH环境变量,我的latex-workshop.latex.tools相关配置如下:
    {
      "command": "latexmk",
      "args": [
        "--shell-escape",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-pdf",
        "-outdir=%OUTDIR%",
        "%DOC%"
      ],
      "env": {"PATH": "/usr/local/texlive/2023/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin"}
    }
    
    但修改后问题依旧,没有任何变化。

我目前使用的是Ubuntu 23.10系统,LaTeX Workshop版本是9.15.0,实在不知道哪里出问题了,希望各位能给我一些建议,非常感谢!

备注:内容来源于stack exchange,提问作者Alex Moreno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 07:44:34