[XeTeX] Detect, whether a font contains a certain character
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon Nov 28 18:35:48 CET 2011
On 28/11/2011 12:34, Tobias Schoel wrote:
> So this seems to work:
>
> \documentclass{minimal}
> \usepackage{fontspec}
> \usepackage{unicode-math}
> \setmathfont{XITS Math}
>
> \usepackage{siunitx}
> \sisetup{%
> detect-all,
> }
>
> \newcounter{works}
> \setcounter{works}{0}
>
> \usepackage{pgffor}
>
> \begin{document}
>
> \newcommand{\ifavailablethenelse}[4]{%#1=font,#2=charcode,#3=then-clause,#4=else-clause
>
> \setcounter{works}{0}
> \bgroup
> \font\test="#1" \test
> \ifnum\XeTeXfonttype\font>0
> \ifnum\XeTeXcharglyph"#2>0
> \setcounter{works}{1}
> \fi
> \fi
> \egroup
> \ifnum\theworks=1
> #3
> \else
> #4
> \fi
> }
>
> \sisetup{math-celsius=foo}
>
> \foreach \phont in {Asana Math,XITS Math, STIXGeneral, Neo Euler}
> {
> \ifavailablethenelse{\phont}{2103}{\sisetup{math-celsius=℃}}{%
> \ifavailablethenelse{\phont}{00B0}{\sisetup{math-celsius=°C}}{
> \sisetup{math-celsius=nix}
> }
> }
> \setmathfont{\phont}
> \(\SI{123}{\celsius}\)
> }
>
>
> \sisetup{text-celsius=bar}
>
> \foreach \phont in {DejaVu Serif, Linux Libertine O, TeX Gyre Pagella,
> Arial}
> {
> \ifavailablethenelse{\phont}{2103}{\sisetup{text-celsius=℃}}{%
> \ifavailablethenelse{\phont}{00B0}{\sisetup{text-celsius=°C}}{
> \sisetup{text-celsius=niente}
> }
> }
> \setmainfont{\phont}
> \SI{123}{\celsius}
> }
> \end{document}
>
> Albeit, it seems to be slow.
I hope you can see why siunitx does not attempt to auto-detect every
available case! (I may slightly alter the XeTeX/LuaTeX defaults, but am
currently testing that this is indeed okay.)
--
Joseph Wright
More information about the XeTeX
mailing list