[XeTeX] Test for font presence

Ron Aaron ron at ronware.org
Tue May 10 10:20:52 CEST 2011


Here's a tested version using 'fc-list'.  It works on kubuntu (and
should work equally well on any *nix, don't know if it would work on
Windows).  Note you need to add "-shell-escape" to the xetex command line:

    \newif\iffontexists
    \newread\fontcheck
    \def\fontexist#1{
        \fontexiststrue
        \immediate\write18{fc-list "#1">fontcheck.tex}
        \immediate\openin\fontcheck="fontcheck.tex"
        \read\fontcheck to \innerfc
        \ifnum\strcmp{\innerfc}{\par}=0
            \fontexistsfalse
        \fi
        \closein\fontcheck
    }
    \def\maybefont#1#2{%
        \fontexist{#1}
        \iffontexists\else
            \def\innermacro##1 {%
                {\bf FONT MISSING: #1}
            }
            \csname#2\endcsname
            \expandafter\let\csname#2\endcsname=\innermacro
        \fi
    }



You would invoke this like "\maybefont{Excellent Font}{excellent}", and
it would check for the font named "Excellent Font", and if it did not
find it would create a new macro "\excellent".  So when you invoked it
later "\excellent12 " (to get 12pt "Excellent Font", you would get "FONT
MISSING: Excellent Font" in your document.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/xetex/attachments/20110510/ae5c2ed6/attachment-0001.html>


More information about the XeTeX mailing list