Fontspec: fall back to other font on missing glyph

Is it possible to tell fontspec to fall back to another font when the main font is missing some glyphs? In the example below, TeX Gyre Termes is missing the SUBSCRIPT ONE glyph (though there doesn't seem to be any warning in the log file!) and I would like to tell luatex to use the glyph from another font such as Libertine.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}
\begin{document}
onesub₁ onesup¹
\end{document}


(I realize that I could use a math subscript in this case, but my content is extracted from a bibliographic database, where it shouldn't be using TeX-specific encodings.)

The log file shows a warning:

Missing character: There is no ₁ (U+2081) in font TeXGyreTermes:mode=node;script=latn;language=DFLT;+tlig;!


You can define an action for the subscript digits:

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}
\setmainfont{TeX Gyre Termes}
\newfontfamily{\fallback}{Libertinus Serif}

\newunicodechar{₁}{%
{\iffontchar\font₁ \else\fallback\fi₁}%
}

\begin{document}

onesub₁ onesup¹

\end{document}


Alternatively, use \textsubscript:

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}
\setmainfont{TeX Gyre Termes}

\newunicodechar{₁}{%
{\iffontchar\font₁ ₁\else\textsubscript{1}\fi}%
}

\begin{document}

onesub₁ onesup¹

\end{document}


• That works well, thanks. Perhaps it would be useful to distribute "font fixup" classes that work around defects in common fonts and version track updates, since it seems that many users would benefit. – Eric Marsden Aug 27 '18 at 11:09