4

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.)

4

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}

enter image description here

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}

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.