如何让 VS Code LaTeX Workshop 选择正确的 Latex 发行版?

如何让 VS Code LaTeX Workshop 选择正确的 Latex 发行版?

我的电脑上安装了两个 Latex 发行版,分别是 Ctex 和 Texlive 2020。VS Code LaTeX Workshop 一直使用 Ctex 来编译 latex 文件。如何强制 VS Code 使用 Texlive 2020 进行编译?

因为某些原因,我需要在这台电脑上保留 Ctex。我的 VS Code LaTeX Workshop 的 settings.json 如下。特别地,我指定了 Texlive 2020 的路径。但是它仍然无法用 Texlive 2020 进行编译。

"latex-workshop.latex.tools": [

    {
    "name": "xelatex",
    "command": "xelatex",
    "args": [
    "-synctex=1",
    "-interaction=nonstopmode",
    "-file-line-error",
    "-pdf",
    "%DOCFILE%"
    ],
    "env": {"TEXMFHOME": "c:/texlive/2020"}
    },
    {
    "name": "pdflatex",
    "command": "pdflatex",
    "args": [
    "-synctex=1",
    "-interaction=nonstopmode",
    "-file-line-error",
    "%DOCFILE%"
    ],
    "env": {"TEXMFHOME": "c:/texlive/2020"}
    },
    {
    "name": "bibtex",
    "command": "bibtex",
    "args": [
    "%DOCFILE%"
    ],
    "env": {"TEXMFHOME": "c:/texlive/2020"}
    },
    {
    "name": "biber",
    "command": "biber",
    "args": [
    "%DOCFILE%"
    ],
    "env": {"TEXMFHOME": "c:/texlive/2020"}
    }
    ],
    "latex-workshop.latex.recipes": [
    {
    "name": "pdf",
    "tools": [
    "pdflatex"
    ]
    },
    {
    "name": "pdf->biber->pdf->pdf",
    "tools": [
    "pdflatex",
    "biber",
    "pdflatex",
    "pdflatex"
    ]
    },
    {
    "name": "pdf->bibtex->pdf->pdf",
    "tools": [
    "pdflatex",
    "bibtex",
    "pdflatex",
    "pdflatex"
    ]
    }
    ],

答案1

我找到了一个解决方案这里。对我来说,在 VS Code 的 settings.json 文件中将“command”更改为“env”是可行的。

"latex-workshop.latex.tools": [

    {
    "name": "xelatex",
    "command": "C:/texlive/2020/bin/win32/xelatex.exe",
    "args": [
    "-synctex=1",
    "-interaction=nonstopmode",
    "-file-line-error",
    "-pdf",
    "%DOCFILE%"
    ]
    },
    {
    "name": "pdflatex",
    "command": "C:/texlive/2020/bin/win32/pdflatex.exe",
    "args": [
    "-synctex=1",
    "-interaction=nonstopmode",
    "-file-line-error",
    "%DOCFILE%"
    ]
    },
    {
    "name": "bibtex",
    "command": "C:/texlive/2020/bin/win32/bibtex.exe",
    "args": [
    "%DOCFILE%"
    ]
    },
    {
    "name": "biber",
    "command": "C:/texlive/2020/bin/win32/biber.exe",
    "args": [
    "%DOCFILE%"
    ]
    }
    ],
    "latex-workshop.latex.recipes": [
    {
    "name": "pdf",
    "tools": [
    "pdflatex"
    ]
    },
    {
    "name": "pdf->biber->pdf->pdf",
    "tools": [
    "pdflatex",
    "biber",
    "pdflatex",
    "pdflatex"
    ]
    },
    {
    "name": "pdf->bibtex->pdf->pdf",
    "tools": [
    "pdflatex",
    "bibtex",
    "pdflatex",
    "pdflatex"
    ]
    }
    ],

答案2

如果您使用 Ubuntu 18.04/20.04,请按照以下步骤操作:

  1. PATH向环境添加变量:
PATH=/usr/local/texlive/2021/bin:$PATH
PATH=/usr/local/texlive/2021/bin/x86_64-linux:$PATH

获取你的 bash 配置。

  1. 关闭所有 VScode 窗口。重新启动 VScode。这在我的系统中有效。希望它也能帮助你。

答案3

Latex Workshop 支持在 shebang 中为每个文件定制 latex 可执行文件,如下所示:

%!TeX program = /Library/TeX/texbin/xelatex
\documentclass[12pt,letterpaper]{report}
% ...

更新:要使上述功能正常工作,latex-workshop.latex.build.forceRecipeUsage必须设置为False

相关内容