Enable xelatex in Latex Workshops for Visual Studio Code

Visual Studio-CodeLatexTexXelatex

Visual Studio-Code Problem Overview


I have a template, which defines all the typesetting recommendations for thesis, but it uses xelatex for compilation. I want to continue using VS Code with Latex Workshops, question is how to change compiler to xelatex from pdflatex. The last one cause next error log:

C:\Users\User\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fontspec\fontspec.sty:45: Fatal Package fontspec Error: The 
fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex"instead of
(fontspec)                      "latex" or "pdflatex".

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

The simplest solution found in issues here, but in more common formulation:

Copying the content, simply go to PreferencesExtensionsLaTeX (meaning LaTeX is LaTeX workshops), find gear-wheel button with name Manage, then find in the list link to settings.json under any tag, open and type next:

"latex-workshop.latex.tools": [{
    "name": "latexmk",
    "command": "latexmk",
    "args": [
        "-xelatex",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOC%"
    ]
}],

Reloading the VSCode may be needed.

Also setting.json file could be found in C:\Users\*\AppData\Roaming\Code\User\settings.json.

Solution 2 - Visual Studio-Code

Use magic comments

add the following line to the beginning of your document.

% !TEX program = xelatex

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionA.AmetovView Question on Stackoverflow
Solution 1 - Visual Studio-CodeA.AmetovView Answer on Stackoverflow
Solution 2 - Visual Studio-Codexiaoou wangView Answer on Stackoverflow