[XeTeX] Detect, whether a font contains a certain character

Ulrike Fischer news3 at nililand.de
Mon Nov 28 12:52:37 CET 2011

Am Mon, 28 Nov 2011 11:44:08 +0200 schrieb Tobias Schoel:

> \XeTeXcharglyph (and Heiko's code) work in text mode. But I also print 
> SI values in math mode, where it doesn't work. See the minimal example:

> \foreach \phont in {Asana Math, XITS Math, STIXGeneral, Neo Euler}
>   {
>   \setmathfont{\phont}
>   \(\ifnum\XeTeXfonttype\font>0
>      7
>      \ifnum\XeTeXcharglyph"2103>0
>        8
>        \sisetup{math-celsius=℃}\SI{123}{\celsius}
>      \fi
>    \fi\)
>   \(\SI{456}{\celsius}\)\\
>   }

> Although u2103 (why did Heiko use u018e=latin capital reversed E?) is 
> only available in Asana Math (which on the other hand doesn't have °) 
> the innermost \if yields true (can be seen by printing the 8 and setting 
> math-celsius to a not-defined glyph).

You are testing the current text font. It works if you use e.g. 

\foreach \phont in {Asana Math, XITS Math, STIXGeneral}


\foreach \phont in {Asana Math, XITS Math, STIXGeneral}
  \font\test="\phont" \test

Then you also don't need math mode. But as you switch fonts, you
should do the test in a group and then set some global value which
you can use outside the group to setup siunitx.

Ulrike Fischer 

More information about the XeTeX mailing list