5

I have installed two Latex distributions on my PC, i.e., Ctex and Texlive 2020. VS Code LaTeX Workshop keeps using Ctex to compile latex files. How do I force VS Code to compile with Texlive 2020?

For some reason, I need to keep the Ctex on this PC. My settings.json of VS Code LaTeX Workshop is as follows. In particular, I have specified the path of Texlive 2020. However, it still cannot compile with 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"
]
}
],

guluzhu
  • 91

3 Answers3

4

I found a solution from here. Changing "command" instead of "env" in the settings.json file of VS Code works for me.

"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"
]
}
],

guluzhu
  • 91
2

If you use Ubuntu 18.04/20.04, follow steps below:

  1. Add PATH variable to the environment:
PATH=/usr/local/texlive/2021/bin:$PATH
PATH=/usr/local/texlive/2021/bin/x86_64-linux:$PATH

Source your bash config.

  1. Close all VScode windows. Restart VScode. This works in my system. Hope it also helps you.
0

Latex Workshop supports to customize latex executable per file in shebang, like below:

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

Update: For the above to work, latex-workshop.latex.build.forceRecipeUsage have to be set to False.

Kato
  • 101
  • 1
    If I'm not mistaken, LaTeX Workshop recently disabled this feature unless you switch latex-workshop.latex.build.forceRecipeUsage to False. – Miyase Apr 03 '22 at 05:47
  • @Miyase Thanks you are right. I have been using 8.21, while this flag has to be turned off in the latest version. I will update this answer. – Kato Apr 04 '22 at 03:44