I am not an expert in LaTeX, but I was writing a paper, everything was going fine, until it suddenly crashed giving me the error:
The fontspec package requires either XeTeX or LuaTeX to function.
I am not an expert in LaTeX, but I was writing a paper, everything was going fine, until it suddenly crashed giving me the error:
The fontspec package requires either XeTeX or LuaTeX to function.
Yes, the fontspec package package requires a compatible compiler or engine, like Xe(La)TeX or Lua(La)TeX. These compilers are better-equipped to handle fonts.
Depending on your compilation protocol (via prompt or command-line, a GUI-like interface or even online), you may have to specify it in the command-line:
xetex <your-tex-file>
xelatex <your-tex-file>
luatex <your-tex-file>
lualatex <your-tex-file>
If you're using some interface like a (La)TeX IDE, then the compiler selection would most likely be somewhere in the interface options. It may even be specified as command-line choice. For example, in TeXnicCenter under Windows, compiler choices can be specified by changing the "Path to the (La)TeX compiler":
Online compilers, like Overleaf, provide similar functionality. You can change the compiler to use a different engine in the project settings. See Changing compiler, where you should select Xe(La)TeX or Lua(La)TeX...
xelatex <document>orlualatex <document>instead ofpdflatex <document>to compile your document if you want to use thefontspecpackage. For some background, try http://tex.stackexchange.com/q/36/86 – Andrew Stacey Oct 04 '12 at 08:49pdflatexinstead ofxelatexfor example) or you addedfontspecexplicitly or a package that loadsfontspecimplicitly. – cgnieder Oct 04 '12 at 11:07XeLaTeXand got this warning. – Tyson Williams Aug 08 '13 at 20:26xelatexin TexStudio but it gave me this error as if I was usingpdfLatex, and if I runxelatexin command line, the file complies. So the bug seems to be in TexStudio. – Yan King Yin Dec 22 '18 at 13:39xelatexthen it works again. Seems to be an update that changed this behavior... – Yan King Yin Dec 23 '18 at 14:02fontspecis pretty clear (we used to use the 'too localized' close reason for that: it's localised in the sense that the user can fix it themselves). I have a feeling there will be other equivalent questions that cover this area: probably one for a meta post before considering reopening. – Joseph Wright Mar 16 '22 at 10:27