3

I'm tyring to built a tex project in VScode. One problem I encountered is that I need to write in Chinese and as such I need to specify the compiler as xelatex rathter than pdflatex. This is not a problem when I'm using texshop, the default IDE I used before, since it allows you to choose the prefered compiler manually. But I don't know how to do that in VScode. So what I do is I added a magic comment in my root file

% !TEX program = xelatex

This is supposed to work, and if my memory served me right, it seems to work before. But for whatever reason, it is no longer working. When I tried to run my tex file, it throws a bunch of 122(!)errors like

Package inputenc: Unicode character 学 (U+5B66) (inputenc) not set up for use with LaTeX.

I am not sure what went wrong with my magic comment and more importantly, how to force VScode to use xelatex.

On this link, you can see the author of latex workshop extention recommend the use of recipe, but honestly I am most confused about where to find the recipe mentioned in the FAQ page and how to edit it.

The author also mentions that magic comment should work as well.

Suppose there is a line % !TEX program = xelatex in the root file. Upon building the project, LaTeX Workshop will parse the root file and figure out that xelatex should be used.

I am on Macbook mid 2014 with texlive 2020. in case this is relevant.

Also, here is my sourcecode. I don't think it is much relevant as I have tried to compile the sourcefile using texshop and it works just fine. So I'm sure it is because of the compiler I chose.

% !TEX program = xelatex
\documentclass{article}
\usepackage{ctex}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{tikz}
\usepackage{adjustbox}
\usepackage[printwatermark]{xwatermark}
\usepackage{biblatex}
%\addbibresource{My literature.bib} 
\usepackage{calc}

\begin{document} \title{学会学习} \date{} \maketitle \newsavebox\watermarkbox \lhead{BeyondWorld Education} \rfoot{学会学习} \renewcommand{\footrulewidth}{2pt} \pagestyle{fancy}

\section{前言} \input{./section/preface}

\section{学习的生物学基础}

\section{如何学习}

\section{如何学习英语} \subsection{单词本} \input{./section/单词本}

\section{应试技巧}

\end{document}

edit: someone on reddit points me to this post But VScode still throws errors, and I don't think I have successfuly forced VScode to use xelatex instead. enter image description here And this is my VScode settings.json file that I assume I need to edit. enter image description here

jxhyc
  • 1,121
  • Possibly related: https://tex.stackexchange.com/questions/462365/how-to-use-latex-on-vs-code , about the settings.json file. – Cicada Jan 15 '22 at 01:58

1 Answers1

1

Magic comments have been disabled by default since December 29, 2021 due to a security risk. Enable it by setting:

latex-workshop.latex.build.forceRecipeUsage: false

Ref: https://github.com/James-Yu/LaTeX-Workshop/issues/3027.

ridfer
  • 11