[XeTeX] Checking if a font exists

Michiel Kamermans pomax at nihongoresources.com
Sun Aug 29 18:24:01 CEST 2010

Hi Alan,

> Is there a way to check whether a font is present in a user's system?  
> I need to generate a document with Myriad Pro if it exists, Arial 
> otherwise, and if neither, exit with an error.

Myriad Pro is nothing like Arial, though... but just to make your life 
worse: thought about version numbers? There are many versions of Myriad 
Pro, and many versions of Arial. How do you know which version numbers 
are permissible?

But let's step back for a moment because there's a fundamental problem 
with your question: if you're using TeX, you're implicitly saying you 
care deeply about the typesetting of your document, which includes being 
particular about which stretches of text use what font. Not just "which 
various fonts look good for this text", but "which font is the one I 
intend to use for this bit of my document". Rather than testing for 
several fonts on a user's machine, and picking "the best match", like if 
the content were styled via (X)HTML+CSS, with a font rule that specifies 
various fonts with fallbals, part of the power of TeX is the fact that 
it will always look the same on any machine it's compiled on, provided 
the dependencies are met. So, either your document will look the same no 
matter what machine it's compiled on, or it doesn't compile. The idea 
that it will compile with Myriad Pro on one machine, and Arial on 
another, basically violates the very idea of TeX.

The better way to solve whatever problem you're having that made you 
wonder how to detect certain fonts is to simply supply those fonts along 
with your .tex source. If other people need to compile your source, 
simply ensure that they have everything they need to compile it?

- Mike "Pomax" Kamermans

More information about the XeTeX mailing list