Atom will not compile when using fontspec package

I'm trying to compile a Beamer document using the fontspec package, but it complains with the following error:

/usr/local/texlive/2015/texmf-dist/tex/latex/fontspec/fontspec.sty:43:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! [ }]


I have found the discussion at this page which suggests it should work fine: font set problems in beamer

I have tried creating an MWE using the code on the answers, such as this (minimised from the original answer):

\documentclass{beamer}
\usepackage{fontspec}
\usetheme{Warsaw}
\setsansfont{Consolas}

\begin{document}

\begin{frame}
frame text goes here
\end{frame}

\end{document}


What am I doing wrong that Beamer can't load fontspec?

Error from the log file:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Fatal fontspec error: "cannot-use-pdftex"
!
! The fontspec package requires either XeTeX or LuaTeX to function.
!
! You must change your typesetting engine to, e.g., "xelatex" or "lualatex"
! instead of plain "latex" or "pdflatex".
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................


Interestingly, I think this has something to do with Atom and the latex package, as TexShop doesn't seem to throw up the same error.

UPDATE: Having checked the .log, at @samcarter's suggestion, it appeared the engine was still typesetting with pdflatex.

After some hunting around, this turned out to be an issue with Atom or, at least, Atom's settings. I have two LaTeX packages installed: latextools and latex.

• Are you using LuaLaTeX to compile the document? I don't experience any problems when compiling your code on a TeXLive2016 system with LuaLaTeX as the format. Any chance you could update your TeXLive distribution from 2015 to 2016? – Mico Dec 5 '16 at 19:45
• also you need to show the actual error message, that will be a multiple line section of the log file from ! to ? show in a code section, so line breaks are preserved. – David Carlisle Dec 5 '16 at 20:20
• But before you update, answer the first question (are you using LuaLaTex (or XeLaTeX)?) The Error message suggests you are not. – pschulz Dec 5 '16 at 20:54
• Ok, thats good. I also can confirm the document working with a current release of XeLaTeX and luaLaTeX. I don't know anything about Atom, sorry. – pschulz Dec 5 '16 at 21:02
• Can you please add the beginning of the log file? This will show if the tex engine you selected is in fact the one used. – user36296 Dec 5 '16 at 21:48

If you're having this problem then the solution can be found in Atom's settings pane.

I have two LaTeX packages installed so I can only comment for these, not others: latextools and latex.

On OS X/macOS:

Atom > Preferences > Packages > latex > Settings


ensure that the Engine is xelatex, and also that:

Atom > Preferences > Packages > latextools > Settings > Builder Settings > Builder Settings Program


is set to xelatex

It may be necessary to flush (delete) logs etc. to enable a clean typeset.