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

Tobias Schoel liesdiedatei at googlemail.com
Mon Nov 28 10:44:08 CET 2011


Hi,

thanks to your answers.

Am 28.11.2011 09:19, schrieb Jonathan Kew:
[snip]

> Assuming the OP is interested in "native" truetype/opentype fonts, not .tfm-based fonts, \XeTeXcharglyph is the simple answer.
>
> JK

As I normally use (Linux Libertine O or TeX Gyre Pagella), Linux 
Biolinum O and Asana Math, I'm interested i "native" opentype fonts.

\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:

\documentclass{minimal}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{DejaVu Serif}
\setmathfont{XITS Math}

\usepackage{siunitx}
\sisetup{%
detect-all,
}

\usepackage{pgffor}

\begin{document}
\sisetup{%
text-celsius=9
}
\foreach \phont in {TeX Gyre Pagella, Linux Libertine O, DejaVu Serif}
  {
  \setmainfont{\phont}
  \ifnum\XeTeXfonttype\font>0
     7
     \ifnum\XeTeXcharglyph"2103>0
       8
       \sisetup{text-celsius=℃}\SI{123}{\celsius}
     \fi
   \fi
  \SI{456}{\celsius}\\
  }


\sisetup{%
math-celsius=9
}
\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}\)\\
  }

\end{document}

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).

Another problem (but that might be due to siunitx): the following 
\SI{456}{\celsius} doesn't know about the \sisetup in the math before. I 
assume this has something to do with grouping and local/global changes. 
But how can I check for glyph availability in math fonts whithout going 
into math mode via \(\)?

Thanks

Toscho


More information about the XeTeX mailing list