[Tex/LaTex] Can’t compile with XeLaTeX on Mac OS High Sierra

macxetex

I've installed MacTex 2017 but can't get anything to compile with XeTex (or LuaLatex). For example this minimal example:

\listfiles\documentclass{article}\usepackage{fontspec}\begin{document}\end{document}

Fails with the following output:

This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./minimal.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.sty
(/Users/ben/Library/texmf/tex/latex/l3packages/xparse/xparse.sty
(/Users/ben/Library/texmf/tex/latex/l3kernel/expl3.sty
(/Users/ben/Library/texmf/tex/latex/l3kernel/expl3-code.tex)
(/Users/ben/Library/texmf/tex/latex/l3kernel/l3unicode-data.def)
(/Users/ben/Library/texmf/tex/latex/l3kernel/l3xdvipdfmx.def)))
! Undefined control sequence.
l.26 \sys_if_engine_luatex:T

The output is basically the same whether I use latexmk or the xelatex command directly. I've tried reinstalling MacTex, and also reinstalling the fontspec package (based on suggestions from similar questions), but nothing seems to work. Can anyone suggest what might be wrong, or how to debug it further?

Best Answer

As pointed out by Joseph Wright, the problem was that a local user texmf directory was present which contained older package files which cause the error with fontspec. Moving (or deleting) the ~/Library/texmf directory fixed the issue.

Related Question