[XeTeX] Determining current font

Will Robertson wspr81 at gmail.com
Mon Jun 9 08:52:49 CEST 2008


On 08/06/2008, at 6:11 PM, Ulrike Fischer wrote:

> The family is stored in \f at family (standard LaTeX} and \zf at family  
> (from
> fontspec) (I don't know if there are cases where the commands give
> different results).

Whenever the \fontspec-like command doesn't change the current font.  
Admittedly, this isn't often. Here's an example:

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\makeatletter
\setmainfont{Georgia}
\setsansfont{Verdana}
\f at family\ vs.\ \zf at family
\end{document}

***

James wanted to be able to query the current font in use. The best way  
to do this, in my opinion (and in this particular circumstance), is to  
ignore what \the\font says and go with \fontname. Here's a macro that  
should do what you want:

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\makeatletter
\newcommand\IfFontIs[1]{%
   \edef\@tempa{\detokenize{#1}}%
   \edef\@tempb{\fontname\font}%
   \expandafter\expandafter\expandafter\in@
   \expandafter\expandafter\expandafter{%
   \expandafter\@tempa\expandafter}\expandafter{\@tempb}%
   \ifin@
     \expandafter\@firstoftwo
   \else
     \expandafter\@secondoftwo
   \fi}
\fontspec{Hoefler Text}
\IfFontIs{Hoefler Text}{yes}{no}
\IfFontIs{Minion Pro}{yes}{no}
\end{document}

Hope this helps,
Will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2415 bytes
Desc: not available
Url : http://tug.org/pipermail/xetex/attachments/20080609/1a37250c/attachment.bin 


More information about the XeTeX mailing list