[XeTeX] If font under fontspec

Will Robertson wspr81 at gmail.com
Tue Sep 21 04:58:08 CEST 2010


On 2010-09-21 09:39:51 +0930, Gareth Hughes 
<garzohugo at gmail.com> said:

> Peter Dyballa wrote:
>> 
>> Am 20.09.2010 um 20:44 schrieb Gareth Hughes:
>> 
>>> I'm asking for a more useful implementation that checks whether a
>>> certain font is in use now
>> 
>> 
>> Wouldn't it be sufficient to check what \{rm,sf,tt}default are set to?
> 
> Perhaps, but a more general, fontspec solution is needed because the
> fonts I want to work with are Syriac fonts. Also, I need to activate
> kerning corrections only when that font is in use, i.e. it would be no
> good to see if the font is being used in a document and then apply the
> kerning corrections for all fonts in the document.

It sort of depends how you want to write the code for the test. Here's 
a proof of concept that might do what you need:

\documentclass{article}
\usepackage{fontspec}

\makeatletter
\newcommand\IsFont[4][]{%
  \begingroup
    \let\current at family\f at family
    \fontspec[#1]{#2}
    \ifx\current at family\zf at family
      \global\let\@tempa\@firstoftwo
    \else
      \global\let\@tempa\@secondoftwo
    \fi
  \endgroup
  \@tempa{#3}{#4}
}
\makeatother

\begin{document}
\newfontfamily\foo{Times New Roman}
\setmainfont{Helvetica}
test: \IsFont{Times New Roman}{Times}{not Times}
\par\foo
test: \IsFont{Times New Roman}{Times}{not Times}
\end{document}


I've considered adding such code to fontspec before. But this interface 
is not very reliable -- font options must be exactly the same for two 
fonts to be "equal". See how you go, though.

Will




More information about the XeTeX mailing list