1

Based on this answer, I try loading a main font and a sans serif font and provide fallbacks for both if the fonts do not exist:

\newif\ifgoodfont
\makeatletter
\ExplSyntaxOn
\cs_set:Nn \__fontspec_load_font:
{
  \__fontspec_font_set:Nnn    \l_fontspec_font
    { \__fontspec_fullname:n {\l_fontspec_fontname_up_tl} } {\f@size pt}
  \__fontspec_font_if_null:NT \l_fontspec_font { 
\global\goodfontfalse
\__fontspec_warning:nx {font-not-found} {\l_fontspec_fontname_up_tl} }
  \__fontspec_set_font_type:
  \__fontspec_font_gset:Nnn   \l_fontspec_font
    { \__fontspec_fullname:n {\l_fontspec_fontname_up_tl} } {\f@size pt}
  \l_fontspec_font % this is necessary for LuaLaTeX to check the scripts properly
}

\cs_set:Nn \__fontspec_load_fontname:n
{
    \__fontspec_load_external_fontoptions:Nn \l_fontspec_fontname_tl {#1}
    \prop_get:NVNF \g__fontspec_fontopts_prop \l_fontspec_fontname_tl \l__fontspec_fontopts_clist
    { \clist_clear:N \l__fontspec_fontopts_clist }
    \__fontspec_font_set:Nnn \l_fontspec_font {\__fontspec_fullname:n {\l_fontspec_fontname_tl}} {\f@size pt}
    \__fontspec_font_if_null:NT \l_fontspec_font { 
\global\goodfontfalse
\__fontspec_warning:nx {font-not-found} {#1} }
}
\ExplSyntaxOff
\makeatother

{\scrollmode\global\goodfonttrue
\setmainfont{Equity Text A}[SmallCapsFont={Equity Caps A}]
}
\ifgoodfont
  \typeout{Using Equity as main font}
\else
  \global\goodfonttrue
  \typeout{Equity not found, trying Libertine...}
  \setmainfont{Linux Libertine O}
  \ifgoodfont
    \typeout{OK}
  \else
    \typeout{Libertine also not found. Using default.}
  \fi
\fi

{\scrollmode\global\goodfonttrue
\setsansfont{Concourse T3}[SmallCapsFont={Concourse C3}]
}
\ifgoodfont
  \typeout{Using Concourse as sans serif font}
\else
  \global\goodfonttrue
  \typeout{Concourse not found, trying TeX Gyre Heros...}
  \setsansfont{TeX Gyre Heros}[Scale=MatchLowercase]
  \ifgoodfont
    \typeout{OK}
  \else
    \typeout{TeX Gyre Heros also not found. Using default.}
  \fi
\fi

However, only the second font actually gets loaded. If I remove the code for the second font, the first font gets loaded. How can I get both fonts to work?

0

You must log in to answer this question.

Browse other questions tagged .