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

Heiko Oberdiek heiko.oberdiek at googlemail.com
Mon Nov 28 01:14:42 CET 2011

On Sun, Nov 27, 2011 at 11:35:29PM +0100, Zdenek Wagner wrote:

> 2011/11/27 Tobias Schoel <liesdiedatei at googlemail.com>:
> > Hi,
> >
> > I know, this question has been raised several times on this list. But I'm
> > bad at searching, so I'm just asking:
> >
> > How can I detect, whether a font contains a certain character (let's say
> > u2103=Degree Celsius symbol) from within XeTeX?
> >
> Put it into an \hbox and measure its width (\wd). If the width is
> zero, the glyph does not exist.

There are chars with zero width, e.g. \not (in math mode).

Partially the test can be done (e.g. for "018E) by:
      % ==> char exists

For the other cases, the \hbox method can be combined with \lastkern,
for example:

  \immediate\write16{glyph does not exist}%
  \immediate\write16{glyph does exist}%

\csname @@end\endcsname\end

Disadvantage: There is a warning in the .log file for missing glyphs:

| Missing character: There is no ... in font cmr10!

Yours sincerely
  Heiko Oberdiek

More information about the XeTeX mailing list