How to catch missing font error and use another font?

I write a TeX-document on two PCs, the files are transferred via USB-Stick. The document should be printed with a specific font. For legal reaons the font is only available on one PC.

When I translate the document in the PC without the font, I get a fontspec error: "font-not-found". (same error in another question)

The finished document shows no characters.

Is there a mechanism to detect this problem and switch to another font?

Actually I change my font selection each time I change the computer. But I want to avoid to use two versions of my style. I would like to have one style for each computer.

A MWE:

\documentclass{article}
\usepackage{fontspec}
%This throws an error - I want to catch it and use another font
\setmainfont{My Font on other PC}
%If error:
%\setmainfont{Arial}
\begin{document}
Test
\end{document}


My wish: This document will be translated without an error with lualatex on a windows PC. If the font My Font on other PC is installed, it is used. If it is not installed, the alternative should be used.

Luatex may let you catch that I'm not sure, but a simpler method that would also work with classic TeX is to simply replace

\setmainfont{My Font on other PC}


by

\input{setdefaultfont}


then anywhere on the tex input path on the two machines you have a setdefaultfont.tex which you do not transfer between the machines.

On one machine the file has the line

\setmainfont{My Font on other PC}


and on the other it has the line

\setmainfont{Arial}

• +1 What I don't like with this solution: setdefaultfont.tex must be defined on each new PC and if I get the font on my 2nd PC, I have to adapt setdefaultfont.tex. Let's see, if another solution will come up. – knut Mar 28 '13 at 20:31
• Instead You might prefer to have \InputIfFileExists{setdefaultfont}{}{\setmainfont{Arial}} then you only need the file on machines which are not going to use arial – David Carlisle Mar 28 '13 at 20:33