[Tex/LaTex] xelatex hangs when using fontspec

fontspecluatexxetex

I'm using TexStudio 2.5.1 on Windows 7 with MiKTeX. The following brief .tex file will cause xelatex to hang:

\documentclass[12pt]{article}
\usepackage{fontspec}
\begin{document}
Test
\end{document}

Using this command to compile:

xelatex.exe -synctex=1 -interaction=nonstopmode "test".tex

By 'hang', I mean that the xelatex process will take up an entire core and 200+ MB of memory, and not finish after several minutes. I get no error messages because the process never finishes.

If I comment out the fontspec line, it doesn't hang. But I'd like to use the fontspec package in my document. Why does it hang and how can I fix it?


As a side note, using lualatex instead of xelatex will succeed, but then using \setmainfont{Georgia} will make that hang as well.

Best Answer

fontspec uses a font caching system. This cache needs to be created first and later updated on a regular basis. Upon creation or updating some information about all TrueType and OpenType fonts installed in your TeX distribution and in your operating system is collected.
(About the algorithms behind collecting and updating, how often or some kind of trigger or so, an expert has to answer.)

Depending on, how many fonts you have installed, these operations take some time, especially on the very first run, of course. That’s the reason, why you observed the hanging in both xelatex and lualatex.

Related Question