Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable xelatex in Latex Workshops for Visual Studio Code

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".
like image 207
A.Ametov Avatar asked May 13 '19 09:05

A.Ametov


People also ask

Can VSCode be used for LaTeX?

Copy and paste the source code into a new LaTeX source file, press “cmd+option+b” to compile, and click the “View PDF Latex file” button on the top-right corner of the VSCode. You can also select “LaTeX Workshop: View LaTeX pdf in external viewer” in the dropdown menu after pressing “cmd+option+p”.

How do I run a VSCode file in LaTeX?

After saving the file, click on the magnifying glass icon on the top right corner. Now it should display the PDF view of your latex document on the right side of the VS Code window. If it doesn't show up, click the TeX icon on the left horizontal menu, and click on "View LaTeX PDF" under the COMMANDS palette.


Video Answer


2 Answers

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.

like image 157
A.Ametov Avatar answered Oct 02 '22 21:10

A.Ametov


Use magic comments

add the following line to the beginning of your document.

% !TEX program = xelatex
like image 39
xiaoou wang Avatar answered Oct 02 '22 21:10

xiaoou wang