I use TeXWorks with XeLaTex. I want to load multiple fonts in my document. When a character doesn't exist in the main font, XeTeX should search the other fonts.

Non-working example:

Holá hello 们 們 안녕 𦮙

That should produce something like this mock-up from MS Word:

Must be

Currently I get:

I Get

I can't mark up each part of the text because this needs to be dynamic. So, as in Word, I need LaTeX to recognize which font contains the character.

  • 2
    Welcome to TeX.SE! – Mensch Mar 29 '19 at 17:37
  • 1
    You might look at the ucharclasses package for an alternative approach. – Davislor Mar 29 '19 at 18:03
  • The literal answer is, \iffontchar, but this would not work well if you have many different fonts to check. tex.stackexchange.com/questions/350896/… – Davislor Mar 29 '19 at 18:03
  • 1
    Another alternative: \babelfont from babel. The polyglossia package has a very similar interface to the one you want, but does not support all the languages in your example. – Davislor Mar 29 '19 at 18:07

The literal answer to the question you asked is that \iffontchar checks whether a font contains the specified glyph, and can be used to implement a fallback. However, I think that is an XY problem.

You can almost do this with ucharclasses. For this MCVE, I used the Noto Sans font family, except for one rare ideograph that I took from Babelstone Han.

\usepackage[Latin, Arabic, CJK, Greek, Korean,

\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}[
\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]

\setTransitionTo{CJKUnifiedIdeographsExtensionB}{\oldchinesefont} % For U+26B99

Holá hello 们 們 안녕 𦮙

Multilingual Text Sample

It doesn’t quite work out of the box for all those languages you requested. First, Simplified Chinese, Traditional Chinese and Korean share many of the same Unicode codepoints, so without further markup, you cannot tell how to render them. Second, it has some problems with right-to-left scripts such as Arabic.

If you wanted to write non-trivial amounts of all those languages in the same document, you would use a package such as Babel and write things like \foreignlanguage{korean}{韓國語} and \DeclareRobustCommand\oldchinese[1]{{\oldchinesefont #1}}.

You could declare individual glyphs with newunicodechar, as in:

\usepackage{fontspec, newunicodechar}
\newfontfamily\oldchinesefont{BabelStone Han}[
  Scale = MatchLowercase,

\newunicodechar{𦮙}{{\oldchinesefont 𦮙}}

This does not play well with ucharclasses, however.

| improve this answer | |

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.