1

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}

1 Answer 1

2

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 {
  luaotfload.add_fallback("myfallback", {
    "Noto Sans CJK SC:mode=harf;",
    "Noto Color Emoji:mode=harf;",
  })
}

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

\begin{document}
سلام\\
hello\\
😄 😁 😆\\
你好
\end{document}
1
  • yes it worked. thank you so much!
    – seyal
    Commented Jun 15, 2022 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .