# Precompile with xelatex and fontspec

I am trying to precompile with xelatex so subsequent compilations could be quick. Here is the MWE. This is the file that I will compile to produce the desired output.

%&myone
%xelatex -ini -jobname="one" "&xelatex" mylatexformat.ltx myone.tex
\begin{document}
Hello World!
\end{document}


This is myone.tex:

%xelatex -ini -jobname="myone" "&xelatex" mylatexformat.ltx myone.tex
\documentclass{article}
\begin{document}
\end{document}


When I issue:

xelatex -ini -jobname="myone" "&xelatex" mylatexformat.ltx myone.tex


It produces an error:

! Can't \dump a format with native fonts or font-mappings.


How do I proceed with precompiling?

• as the error message says, you can not dump system font loading into the format (luatex has similar restrictions). – David Carlisle Oct 13 '17 at 7:44
• @DavidCarlisle I am not an expert. But does this not defeat the very idea of precompiling? Also, is there a workaround? – deshmukh Oct 13 '17 at 11:54
• the format of format files was determined in around 1980 several decades before opentype fonts were invented so defeat or not that is just the way it is. you can of course arrange to load as much tex macros (eg big packages like tikz) but in xetex and luatex you need to leave the font loading until runtime. – David Carlisle Oct 13 '17 at 11:58
• @DavidCarlisle OK. I have now dropped all references to fonts, etc. and still get the same error while pre-compiling. Is it that it is just not possible to pre-compile using xelatex? Please see the update question. – deshmukh Oct 14 '17 at 6:09

xelatex can not dump a format after an OpenType font has been loaded. By default xelatex uses TU (Unicode) encoding as the initial default, so when the class does \normalfont OpenType latin modern is used and dump is disabled.

This sets the default back to classic 7-bit TeX encoding, then the tfm latin modern will be used during initex run, and TU is re-enabled in \everyjob

\def\encodingdefault{OT1}\normalfont
\everyjob\expandafter{\the\everyjob\def\encodingdefault{TU}\normalfont}
\documentclass{article}
\begin{document}
\end{document}


with a log of

.....
Beginning to dump on file myone.fmt