[XeTeX] Determining current font

James Crippen jcrippen at gmail.com
Mon Jun 9 23:56:05 CEST 2008


On Sun, Jun 8, 2008 at 8:52 PM, Will Robertson <wspr81 at gmail.com> wrote:
> 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}

Of course, for everyday use we'll need \makeatother right here.

I'm not even going to pretend that I can figure out all those
\expandafter calls.

> \fontspec{Hoefler Text}
> \IfFontIs{Hoefler Text}{yes}{no}
> \IfFontIs{Minion Pro}{yes}{no}
> \end{document}

This does exactly what I asked for! It's wonderful!

Now I have one more question, which is probably much harder. When you
use a \fontspec or \fontfamily you get a macro that (among other
things) does this:

{\noexpand\fontfamily{\zf at family}\noexpand\selectfont}

What I'm wondering is if there's a way to get the value of \zf at family
out of the macro, so that I could say something like

\newfontfamily{\myfont}[Bold={* Semibold},...]{Minion Pro}
\IfFontMacroIs{\myfont}{...}{...}

Such that \IfFontMacroIs would give the same results as
\IfFontIs{Minion Pro}{...}{...}.

Is this possible? It's probably asking a lot, and I won't be sad if it
requires too much black magic.

I heartily recommend that you add \IfFontIs to fontspec, perhaps
naming it something like \ifcurrentfont.

Thanks a bunch,
James


More information about the XeTeX mailing list