如何检测哪种字体包含字符?

如何检测哪种字体包含字符?

我使用 TeXWorks 和 XeLaTex。我想在文档中加载多种字体。当主字体中不存在某个字符时,XeTeX 应该搜索其他字体。

非工作示例:

\documentclass[a4paper,10pt]{article}
\usepackage{fontspec}
\setmainfont{Arial}
\newfontfamily\koreanfont{korean.ttf}
\newfontfamily\tradchinesefont{trad-chinese.ttf}
\newfontfamily\simpchinesefont{simp-chinese.ttf}
\newfontfamily\oldchinesefont{old-chinese.ttf}
\newfontfamily\greekfont{greek.ttf}
\newfontfamily\arabfont{arab.ttf}
\begin{document}
Holá hello 们 們 안녕 

答案1

对你提出的问题的字面答案是\iffontchar检查字体是否包含指定的字形,并可用于实现回退。但是,我认为这是XY 问题

你可以几乎用 来做这件事ucharclasses。对于这个 MCVE,我使用了 Noto Sans 字体系列,除了从 Babelstone Han 中取来的一个罕见表意文字。

\usepackage{fontspec}
\usepackage[Latin, Arabic, CJK, Greek, Korean,
            CJKUnifiedIdeographsExtensionB
           ]{ucharclasses}

\defaultfontfeatures{Scale = MatchLowercase, Ligatures = TeX}
\setmainfont{Noto Sans}[Scale = 1.0]
\setsansfont{Noto Sans}

\newfontfamily\koreanfont{Noto Sans CJK KR}[
  Language=Korean, Script=CJK]
\newfontfamily\tradchinesefont{Noto Sans CJK TC}[
  % CJKShape = Traditional,
  Language=Chinese Traditional, Script = CJK]
\newfontfamily\simpchinesefont{Noto Sans CJK SC}[
  % CJKShape = Simplified,
  Language=Chinese Simplified, Script = CJK]
\newfontfamily\oldchinesefont{BabelStone Han}[
  Script=CJK]
\newfontfamily\greekfont{Noto Sans}[
  % Language = Greek,
  Script = Greek]
% WARNING: RTL scripts require polyglossia or babel to work correctly!
\newfontfamily\arabfont{Noto Sans Arabic}[
  Script = Arabic]

\setTransitionsForArabics{\arabfont}{}
\setTransitionsForChinese{\simpchinesefont}{}
\setTransitionsForKorean{\koreanfont}{}
\setTransitionsForGreek{\greekfont}{}
\setTransitionTo{CJKUnifiedIdeographsExtensionB}{\oldchinesefont} % For U+26B99

\begin{document}
Holá hello 们 們 안녕 

相关内容