# How can I get babel to use a fallback font when a special character is missing from the main font?

Sometimes there is a character in my text that is not in the main font, such as Chinese characters or emojis, etc. and I do not want to constantly modify this in the text with various commands to change the font.

I know this can be done by changing the language, but I want LuaLateX itself to check a font list and use the character from theses fonts, when a character is not available in the main font.

This idea came to me when I saw this answer about using emojis in text: Substituting fonts for emojis in LuaLaTeX

Is it possible to use such an algorithm for LuaLaTeX and babel package with directlua?


\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelprovide[import, main]{arabic}
\babelfont{rm}{Amiri}
%%how force latex to use another font if an special charchter is not in Amiri font?
\begin{document}
سلام\\
hello\\
😄 😁 😆\\
你好
\end{document}


You can just extend the provided fallback to more than one font and pass it normally.

\documentclass{article}

\usepackage[bidi=basic]{babel}
\babelprovide[import, main]{arabic}

\directlua {
"Noto Sans CJK SC:mode=harf;",
"Noto Color Emoji:mode=harf;",
})
}

\babelfont{rm}[RawFeature={fallback=myfallback}]{Amiri}

\begin{document}
سلام\\
hello\\
😄 😁 😆\\

\end{document}

• yes it worked. thank you so much! Jun 15 at 6:25