# xelatex problem: Missing chars in TeXLive 2013 / \textfont XXX is undefined errors in miktex

I'm trying to track down the source of a problem with the new xetex binary in miktex. I think it is related to the following problem in TeXLive 2013:

\documentclass{article}
\usepackage{unicode-math}
\begin{document}
%$a_a$

\message{missing chars}
$a_{aa_{aa}}$
\end{document}


gives in the log-file the message:

Missing character: There is no ƽ in font [latinmodern-math.otf]/ICU:script=math
;language=DFLT;+ssty=1;!
Missing character: There is no ǅ in font [latinmodern-math.otf]/ICU:script=math
;language=DFLT;!


The missing char mentioned in the log-file can change in subsequent math. And in most cases I get it only if there is at least two symbols in the subscript. Previous math can change the behaviour. Has anyone an idea what going on here? Where does the missing character message comes from?

Additional info: The missing char (and the error in miktex) appears at the closing math shift. So what is xelatex doing there which could give an font error?

# Edit

More or less by chance I found out that the problem disappears (also in miktex) if one reload a math font with a range option and I could track down the effect to this line in the range code:

\documentclass{article}
\usepackage{unicode-math}

\ExplSyntaxOn
\keys_define:nn {unicode-math} {
nobug .code:n = {
\cs_set_eq:NN \um_map_char_single:nn \um_map_char_parse:nn
}}

\keys_define:nn {unicode-math} {
bug .code:n = {
\cs_set_eq:NN \um_map_char_single:nn \um_map_char_noparse:nn
}}

\ExplSyntaxOff

%\setmathfont[bug]{Latin Modern Math}
\setmathfont[nobug]{Latin Modern Math}
\begin{document}

$a^{aa^{aa}}$

\end{document}


The \um_map_char_noparse:nn sets mathcode, so the next step is to find out, why this disturbs the new xetex version.

# Edit 2

I found out that the number in the error message in miktex (\textfont XXX is undefined) and the missing chars change if I use the ^^-notation before the math. With every additional use of ^^ the numbers/chars "count down". In TeXLive the missing char message disappears sometimes (obviously because the currently requested char is in the font). If there is no \par between the ^^21 the steps are smaller. Three or more ^^^ change the steps too.

That's all very curious, and I suspect some error in the handling of the ^^-notation -> this hypothese seems to be wrong see Edit 4.

\documentclass{article}
\usepackage{unicode-math}

\begin{document}
%        font name     TL missing char
%no ^^:  %197  .5      char 453

%uncomment one-by-one to see changes in error/missing char message

%^^21    %142  .5      char 398

%^^21    %91   .5      -

%^^21    %40   .5      -

%^^21    %245  ^^@     -

%^^21    %194  ^^@     -

%^^21    %143  ^^@     ^^8f

% other char as superscript, only to avoid side effects:
% it doesn't change the behaviour
\catcode\?=7
$k?{kk}$

\end{document}


# Edit 3

An example emerged (MiKTeX Update: Error \textfont is undefined with Package url) which doesn't use unicode-math.

miktex users get error message directly, while in TeXLive 2013 on has to add some ^^21 to get the "missing char" message in the log-file:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[]{LinLibertine_R.otf}
\usepackage{url}
\urlstyle{rm}

\begin{document}
^^21

^^21

^^21

^^21

^^21

Test: \url{http://test-website.com}
\end{document}


The error happens only with the specific font. With e.g. LinLibertine_RB.otf there is no error.

# Edit 4

Joseph Wright analysed the example in edit 3 and came up with an example which doesn't used the ^^-notation but simple chars to "count down" the error/missing char numbers. I also tried to find out what is so special about the libertine font and I think it has to do with math properties: Unlike LinLibertine-M.otf the font set math values like DelimitedSubFormulaMinHeight. Tests with other "math open type" fonts seem to confirm this:

\documentclass{article}
\usepackage[no-math]{fontspec}

\setsansfont{Cambria Math}% or some other font with "math properties"
% like LinLibertine_R.otf or latin modern math
% it doesn't matter if it used outside math
\ExplSyntaxOn
\SetMathAlphabet\mathsf{normal}\g_fontspec_encoding_tl\sfdefault\mddefault\updefault
\ExplSyntaxOff

\begin{document}
A

A

$% \mathsf{a_{aa}}\showoutput%$%
\end{document}


# Work-around (not very good)

It seems that the error messages don't affect the end document. So one can remove unicode-math and load fontspec with the no-math option while writing the document and reenable the wanted math setup at the end and then compile with scrollmode to ignore all errors.

# Edit 5 - a fix is in view

Khaled Hosny has committed a fix: https://github.com/khaledhosny/xetex/commit/b9f323a. Hopefully this will solve the issue in the more or less near future.

# Edit 6 - Joy and Happiness

Today's update of the xelatex binary seems to have solved the problem for miktex.

-
It happens also on TeX Live 2013 (Mac OS X, 10.8.4, MacTeX). –  egreg Jul 7 '13 at 16:17
Just for completeness: This issue has been raised here and here on tex.sx. @UlrikeFischer's mails on the XeTeX mailing list are here and here –  dapperdan Aug 16 '13 at 8:57
@dapperdan: I wrote Khaled an email and he answered me. I also informed him by mail about the content of edit 2 (without answer until now). It would be probably not a bad idea to add something to the xetex bug tracker so that the problem doesn't get lost, so do it. –  Ulrike Fischer Aug 16 '13 at 9:00
@JosephWright: Yes the example is also meant for TL2013. I explictly added enough ^^21 to "count down" to a missing char in TL2013. I see there (only in the log) the message Missing character: There is no ^^90 in font [LinLibertine_R.otf]/ICU:script=lat n;language=DFLT;!`. But as the error is obviously font dependant it is possible that it can't be seen on all systems. –  Ulrike Fischer Aug 18 '13 at 17:01
@matth: The warning is harmless. You can add an empty kanjix.map to get rid of it. Or wait: I made a bug report. –  Ulrike Fischer Sep 2 '13 at 8:38