fontspec LuaTeX error

I have installed "ProTeX" with "TeXstudio 2.3" & "Miktex 2.9". I get an error

! The fontspec package requires either XeTeX or LuaTeX to function


when I attempt to run

\documentclass{article}
\usepackage{fontspec}

\begin{document}
Hello world!
\end{document}


MikTeX is said to come with some of this installed.

You have to reconfig TeXstudio to use lualatex or xelatex instead of pdflatex which is preconfigured in TeXstudio. You can change it under options, then commands.

You can also use the command line to test whether for example lualatex is running. lualatex test will compile test.tex with lualatex.

• 'comands' reads "latex -src -interaction=nonstopmode %.tex". How should it then read? Sep 14, 2012 at 8:42
• If you are pressing F6 in running your pdflatex, replace pdflatex in pdflatex -synctex=1 -interaction=nonstopmode %.tex with either lualatex or xelatex. Sep 14, 2012 at 9:24
• Oh, I hope you don't mind. I think the comment was harmless enough. :) Sep 14, 2012 at 12:50
• Thank you for answering. I'm going to learn fast, with everyones help in this forum. Sep 18, 2012 at 6:45
• The update of TexStudio seems to have changed this... I have to reset the default to xelatex. Dec 23, 2018 at 14:00

If you insist on TeXStudio you may now download TeXStudio 2.4. You can now set up your xelatex and lualatex commands with this version.

I am using Ubuntu 12.04 but TeXStudio 2.4 must have the same features as the Windows version.

See in the picture below that there is already a separate box your xelatex and lualatex commands.

Now, in the build option, choose your default compiler. You may now choose either xelatex or lualatex. See picture below.

If you don't want to update just yet, you may look at my comment in this answer.

But it is a hassle to keep on changing your default compiler. Some times it is better to just open cmd and run xelatex myfile.tex or lualatex myfile.tex. Just CD to your source folder before doing the compile.

• I downloaded 2.4. I works great. I love the software improvements. Sep 18, 2012 at 6:36
• I'm glad it helped. Sep 18, 2012 at 6:52

You should compile the document with xelatex or lualatex command. For me, your document compiles with both with no errors.

• I am an old pre-CP/M nerd. I don't use command line stuff if I can help it. Thanks for your answering my cry for help. Sep 18, 2012 at 6:42

Also in the MiKTeX Settings (Options window) under the “Formats” tab one must activate the creation of format files (needed for fonts!) for lualatex, luatex, xelatex and xetex:

Select every single of them, click on ‘Change…’ and in the dialogue window “Format Definition” deactivate ‘Exclude this format when updating all format files’.

Then, very important, go to the “General” tab and update all format files, what creates also the new ones, followed by a refresh of the filename data base (FNDB).

• I have done the above plus exclude Latex, Pdflatex, "Update Formats", and have the same error. Sep 14, 2012 at 8:23
• @Optionparty: My answer is an addition to the others. You didn’t say anything to them. But also important: I’ve forgotten a second step, see my edit. Sep 14, 2012 at 15:26