How to activate font fallbacks on typefaces in ConTeXt?

This is a follow-up to my previous question about setting the tt font in mathtt. As Henri Menke stated in a comment using typefaces should be preferred over font families. So I tried to convert the code given in his answer. The result is the following MWE:

``````\starttypescript[test]
\definetypeface [test] [rm] [serif] [pagella]
\definetypeface [test] [tt] [mono] [firacode]
\definefontfallback [ttupper] [firacode] [uppercasenormal] [offset=uppercasemonospace,force=yes]
\definefontfallback [ttlower] [firacode] [lowercasenormal] [offset=lowercasemonospace,force=yes]
\definetypeface [test] [mm] [math] [pagella] [default] [fallbacks={ttlower,ttupper}]
\stoptypescript
\setupbodyfont  [test,12pt]

\starttext
Test \type{Text} with \$\mathtt{TEST}\$
\stoptext
``````

Unfortunately, ConTeXt does not use the fallbacks I specified. How does the fallback mechanism work with typefaces?

• `\definefontfallback` needs a font lookup as the second argument, either via `name:<name>`, or `file:<file>`. – Henri Menke Apr 20 '19 at 8:24

You can only use fallbacks with `\definefontsynonym`, so you have to define a typescript. Of course the typescript definition would go in an environment file in your larger project. You can also take a look at this answer of mine to find out how to install fonts and typescript system-wide.

``````\loadtypescriptfile[texgyre]

\definefontfallback [firaoverpagella] [file:FiraMono-Regular.otf] [uppercasenormal] [offset=uppercasemonospace,force=yes]
\definefontfallback [firaoverpagella] [file:FiraMono-Regular.otf] [lowercasenormal] [offset=lowercasemonospace,force=yes]

\starttypescript [mono] [firamono] [name]
\definefontsynonym [Mono]     [file:FiraMono-Regular.otf]
\definefontsynonym [MonoBold] [file:FiraMono-Bold.otf]
\stoptypescript

\starttypescript [math] [firaoverpagella]
\definefontsynonym [MathRoman] [texgyrepagella-math] [features={math\mathsizesuffix,mathextra},fallbacks=firaoverpagella]
\stoptypescript

\starttypescript [pagella-with-fira]
\definetypeface [\typescriptone] [rm] [serif] [pagella]          [default]
\definetypeface [\typescriptone] [ss] [sans]  [pagella]          [default]
\definetypeface [\typescriptone] [tt] [mono]  [firamono]         [default]
\definetypeface [\typescriptone] [mm] [math]  [firaoverpagella]  [default]
\quittypescriptscanning
\stoptypescript

\setupbodyfont [pagella-with-fira,12pt]

\starttext
Test \type{Text} with \$\mathtt{TEST}\$
\stoptext
``````

• I couldn't test yet, but according to `setup-en.pdf` there is a `fallbacks` option key for `\definetypeface`. Is that deprecated or just infunctional? – TeXnician Apr 20 '19 at 6:58
• @TeXnician I could only find one reference to `fallbacks` in the `\definetypeface` source, which is not very insightful. Also none of the bundled typescripts seems to use `fallbacks` with `\definetypeface`. I think it just doesn't work. – Henri Menke Apr 20 '19 at 8:22