2

We use as main font Liberation Sans which misses many of the unicode characters. As far as I understand DejaVu Sans has many of them. Is there a way to automagical (!) switch the font in case lualatex complains about a missing character?

{/usr/share/texmf/fonts/map/pdftex/updmap/pdftex.map}
Missing character: There is no ☎ (U+260E) in font LiberationSans:mode=node;scr
ipt=latn;language=dflt;+tlig;!

MWE

\documentclass[a4paper,11pt,english]{article}
\usepackage{fontspec}
\usepackage[shorthands=off,bidi=basic]{babel}
\setmainfont{Liberation Sans}
%\setmainfont{DejaVu Sans}

\begin{document}
Kontakt: ☎️ 
\end{document}

So the main idea is to define a fallback when the default misses the character. If the fallback doesn't have the character than that's fine. But at least one level would be great.

Using: LuaHBTeX, Version 1.12.0

4
  • 2
    see the luaotfload documentation, or e.g. tex.stackexchange.com/a/572220/2388 Commented Dec 28, 2020 at 17:27
  • I posted a working sample as answer. Although I've copied the code from the docu I'm highly unclear why I need script=grek. Could you add a hint in the answer (as well as in the docu)? Thx.
    – LeO
    Commented Dec 28, 2020 at 19:24
  • you don't need script=grek, it is optional (in case you want to force a script). Commented Dec 28, 2020 at 19:30
  • Sorry, if I'm persistent. But why is it than mentioned in docu? (As sample fallback)
    – LeO
    Commented Dec 28, 2020 at 19:37

2 Answers 2

4

Thx to Ulrike I found the following working sample

\documentclass[a4paper,11pt,english]{article}
\usepackage{fontspec}
\directlua{luaotfload.add_fallback
("emojifallback",
    { "DejaVu Sans:mode=harf;script=grek",
     "NotoColorEmoji:mode=harf"}
)}

\setmainfont{Liberation Sans}[RawFeature={fallback=emojifallback}]

\begin{document}
Kontakt: ☎️ » 🂡 🤦
\end{document}

The luaotfload is automatically loaded with luaHBTeX. I have copied the sample from the documentation.

1

You can declare a particular character active, which lets you specify what font you want each individual symbol to come from, and also works in XeTeX or PDFTeX.

\documentclass[a4paper,11pt,english]{article}
\tracinglostchars=2
\usepackage[shorthands=off,bidi=basic]{babel}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmainfont{Liberation Sans}

\newfontfamily\emojifont{Noto Color Emoji}[
  Scale=MatchUppercase,
  Renderer=HarfBuzz ]

\newunicodechar{^^^^260e}{{\emojifont\symbol{"260E}}} % ☎️ 

\begin{document}
Kontakt: ☎️ 
\end{document}

Noto Color Emoji sample

2
  • Yeah, it meets my request but makes also clear that wording is sometimes tricky ;-) I have seen this approach already but have the major problem that I have to know the characters in advance. And when you cannot limit the input (e.g. since you auto generate tex) its getting tricky.
    – LeO
    Commented Dec 29, 2020 at 9:35
  • @LeO In XeTeX, the ucharclasses package lets you do it for entire Unicode blocks.
    – Davislor
    Commented Dec 29, 2020 at 13:03

You must log in to answer this question.

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