49

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.

Stephen
  • 14,890
mklb1
  • 491
  • 17
    That means that you have to use xelatex <document> or lualatex <document> instead of pdflatex <document> to compile your document if you want to use the fontspec package. For some background, try http://tex.stackexchange.com/q/36/86 – Andrew Stacey Oct 04 '12 at 08:49
  • 3
    This can't have happened suddenly. Either you changed how you compile your document (now using pdflatex instead of xelatex for example) or you added fontspec explicitly or a package that loads fontspec implicitly. – cgnieder Oct 04 '12 at 11:07
  • As the error message said, LuaLaTeX or XeLaTeX should be used. Probably it wasn't the case. Since no further information was given, the question will now be closed as too localized. – Stefan Kottwitz Oct 18 '12 at 12:20
  • @Stefan I tried compile a document with XeLaTeX and got this warning. – Tyson Williams Aug 08 '13 at 20:26
  • 2
    I got this same error and there's no answer. Wonder why this question is closed. – Yan King Yin Dec 22 '18 at 13:31
  • I clearly chose xelatex in TexStudio but it gave me this error as if I was using pdfLatex, and if I run xelatex in command line, the file complies. So the bug seems to be in TexStudio. – Yan King Yin Dec 22 '18 at 13:39
  • I had to change the default command to xelatex then it works again. Seems to be an update that changed this behavior... – Yan King Yin Dec 23 '18 at 14:02
  • Why was this question closed? It has 41 upvote. It is relevant to the entire planet Earth, it is specific to all times when the fontspec package exists, and it is relevant to every situation in which you use this package. So it is "generally applicable to the worldwide audience of the internet". None of the reasons for which this question was closed are applicable. Please reopen it so someone can post a proper answer instead of abusing comments to post answers. – Hubert Schölnast Mar 16 '22 at 10:10
  • @HubertSchölnast I think this one was closed as it's user error: the message from fontspec is 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
  • @JosephWright: I became a directory from a collegue with a tex file, a cls file, font files etc. and I tried to compile it in overleaf.com. I got the error "The fontspec package requires either XeTeX or LuaTeX to function", my collegue is on vacation and I still don't know what I need to change in which document to get it compiled. Btw: The message is not pretty clear to me. Maybe it is clear to Latex-experts, but I am an newbie and I don't understand what this message wants to tell me. I never heard of "XeTeX" or "LuaTeX" before. – Hubert Schölnast Mar 16 '22 at 12:11
  • @HubertSchölnast: In Overleaf, 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... – Werner Mar 16 '22 at 17:38
  • Thank you @Werner, I think this might help, but I still think it is not ok to get answers like yours via comments to a good question that is closed for reasons most people don't understand. Please reopen it (I can't, I don't have enough privileges) and post proper answers instead of comments. – Hubert Schölnast Mar 17 '22 at 08:03

1 Answers1

5

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.

How do you use Xe(La)TeX or Lua(La)TeX?

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":

enter image description here

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...

Werner
  • 603,163