The following error seems to pop up on many BasicTeX distributions lately when using fontspec with xelatex or lualatex (see e.g. here, here, here or here):
/usr/local/texlive/2016basic/texmf-dist/tex/latex/base/tuenc.def:252: Missing \endcsname inserted.
Here's a MWE to reproduce this issue (both xelatex and lualatex yield the same error):
\documentclass{article}
\usepackage{fontspec}
\begin{document}
This is a test.
\end{document}
The problem seems to be related to an old version of LaTeX and seems to have started when the fontspec package was updated at some point. I keep my distribution up to date with tlmgr. I have never installed any local formats (that is I have never run fmutil or fmutil-sys), and I have completely removed ~/Library/texlive. All this happens on a fresh install of macOS Sierra. I have also completely reinstalled BasicTeX, but nothing solves this issue.
Here are the versions of pdflatex, xelatex, and lualatex just in case this might be relevant:
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
This is XeTeX, Version 3.14159265-2.6-0.99996 (TeX Live 2016) (preloaded format=xelatex)
This is LuaTeX, Version 0.95.0 (TeX Live 2016)
Also, each binary reports the following version of LaTeX2e (not sure if this is important, but it's a 2016 date):
LaTeX2e <2016/03/31>
Update
I figured out where the problem occurs by reinstalling everything. After installing BasicTeX, everything works. However, updating TeX results in an error message.
First, this works fine:
sudo tlmgr update --self
Next, I update all packages with:
sudo tlmgr update --all
This gives me an error somewhere down the packages:
[61/78, 00:27/00:27] update: xebaposter [12k] (39709 -> 42046) ... done
[62/78, 00:28/00:28] update: xecjk [124k] (41129 -> 43308) ... done
tlmgr: inconsistency on (one of) the server(s):
http://mirror.easyname.at/ctan/systems/texlive/tlnet
tlmgr: tlp for package xepersian cannot be found, please report.
[63/78, 00:28/00:28] update: xetex [47k] (40963 -> 41438) ... done
[64/78, 00:28/00:28] update: xetexko [56k] (40374 -> 43173) ... done
And still further down:
[76/78, 00:30/00:30] update: collection-xetex [1k] (40404 -> 43059) ... done
[77/78, 00:30/00:30] update: scheme-small [1k] (41261 -> 41825) ... done
tlmgr: action update returned an error; continuing.
tlmgr: package log updated: /usr/local/texlive/2016basic/texmf-var/web2c/tlmgr.log
running mktexlsr ...
done running mktexlsr.
running updmap-sys ...
done running updmap-sys.
regenerating fmtutil.cnf in /usr/local/texlive/2016basic/texmf-dist
tlmgr: An error has occurred. See above messages. Exiting.
I guess this explains why the formats were not updated. It's not this particular mirror, because I get the same error with a different one.
tuenc.defwas updated butlatex(or whatever package is affected) is not. – cbrnr Mar 14 '17 at 12:12kpsewhich latex.ltxsays and check around line 699 it should say\edef\fmtversion {2017/01/01}in which case the question is why isn't your format updated. If the latex source still says 2016 then the (different) question is how come that didn't get updated. You are lucky really that change happened to make an error in a recent release as otherwise you silently miss the fact that all updates are broken (you are 7 latex releases behind ctan) – David Carlisle Mar 14 '17 at 12:15INPUT /usr/local/texlive/2016basic/texmf-dist/tex/latex/base/tuenc.def. – cbrnr Mar 14 '17 at 13:14latex.ltxit says\edef\fmtversion {2017/01/01}. – cbrnr Mar 14 '17 at 13:16/usr/local/texlive/2016basic/texmf-var/web2c/xetex/xelatex.fmt. – cbrnr Mar 14 '17 at 13:45fmtutil-sys --allshould be enough but I have no idea why the formats were not remade when latex was updated. – David Carlisle Mar 14 '17 at 16:53pdflatexon any document and report what date it puts in the banner. – David Carlisle Mar 15 '17 at 08:05fmtutil-sys --alldid it fix the problem? – David Carlisle Mar 15 '17 at 08:06sudo fmutil-sys --alldid fix the problem, thanks! I've added the versions at the bottom of my question. It's almost certainly not a bug in the packages because this seems to be a Mac-specific issue. Now the question is if and how to report this issue... – cbrnr Mar 15 '17 at 08:36tlmgr install --reinstall latex latex-bin ucstrying to get something else fixed. Ran into the OP described error, runningfmutil-sys --allfixed it. – Ahmed Masud Mar 30 '17 at 01:55