3

Consider this MWE:

\documentclass{article}
\usepackage{fontspec}

\directlua{luaotfload.add_fallback("noto_fallback", 
{
    "NotoSerif:mode=base;color=FF8800;",
})}

\setmainfont{Source Serif Pro}
[RawFeature={fallback=noto_fallback;color=A0A0A0}]
\setsansfont{Source Sans Pro}

\begin{document}
\section*{Some Polytonic Greek}
\setlength\parindent{0pt}
\setlength\parskip{1.5ex}

Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα,  ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον.

\sffamily
As you can see, \emph{Source Serif Pro} (grey) contains some, but not 
all required glyphs, which are then pulled from my fallback 
font \emph{Noto Serif} (orange). I'd like all Greek characters to be 
taken from Noto Serif (i.e., be orange in this example.)

\end{document}

My text is mainly in English (German, actually, but this doesn't matter), but requires some interspersed Polytonic Greek. I have a font which could handle all my Greek needs specified as a fallback: How can I get LuaLaTeX to pull all Greek glyphs from that font, for consistency's sake?

enter image description here

8
  • Do you mean without using babel, e.g., some lua code to remove Greek from Source Serif Pro, or substitute it with or map to Noto Serif Greek?
    – Cicada
    Jun 19, 2022 at 6:20
  • I was potentially thinking of some Lua code to restrict Source to all non-Greek characters, I suppose, but I'm open to all suggestions (I normally do use Babel). Specifying glyph ranges, remapping – whatever gets the job done.
    – Ingmar
    Jun 19, 2022 at 6:39
  • Your comment made me think: Obviously something like \newfontfamily{\poly}{NotoSerif} would work, but I'm still hoping for a fully automatic solution.
    – Ingmar
    Jun 19, 2022 at 7:09
  • \usepackage[greek,english]{babel} \babelprovide[import, onchar = fonts ids]{greek} \babelfont[greek]{rm}[Colour=orange]{Noto Serif} \setmainfont{Source Serif Pro} automatically catches the glyphs, but not punctuation (,,.), so not 100%.
    – Cicada
    Jun 19, 2022 at 8:07
  • polyglossia catches glyphs and punctuation, but needs \selectlanguage{greek} switches, so not automatic.
    – Cicada
    Jun 19, 2022 at 8:27

2 Answers 2

4

babel package can detect which Unicode block a glyph belongs to and automatically change fonts, but punctuation and digits (and space) are in the Latin quarter of Unicode and so don't change even when they are surrounded by Greek.

babel

MWE

\documentclass{article}
\usepackage[greek,english]{babel}
\babelprovide[import, onchar = fonts ids]{greek}
\babelfont[greek]{rm}[Colour=FF8800]{Noto Serif}
\setmainfont{Source Serif Pro}
\begin{document}

 Some text here. Consider the following:

Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα,  ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον.


\end{document}

polyglossia handles text and punctuation (and other things) but requires manual switching with \selectlanguage{greek}, so not automatic.

polyglossia

MWE

\documentclass{article}
\usepackage{polyglossia}
 \setmainlanguage{english}
 \setotherlanguage[variant=polytonic]{greek}
 \newfontfamily\greekfont{Gentium Plus}[Colour=FF8800]

 \begin{document}

 Some text here. Consider the following:

\selectlanguage{greek}
Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα,  ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον.

\end{document}
3
  • 1
    Of course, manual switching is available in babel, too. Jun 20, 2022 at 15:59
  • Thank you for this answer. I still get a warning "Language 'Greek' not available for font 'NotoSerif' with script 'Greek'" but it seems to be safe to ignore for now.
    – Ingmar
    Jun 20, 2022 at 17:22
  • 1
    Yes, fontspec info. Noto Serif is not a Greek font (i.e., it doesn't have the otf script/language setup for grk). Default script/language is OK.
    – Cicada
    Jun 21, 2022 at 6:39
6

In most cases it is best to use the babel support Cicada mentioned since it can also adjust e.g. hyphenation patterns and has a nicer user interface, but if you only care about the font then luaotfload has a multiscript feature which works similar to fallback, except that it selects the font based on the used script instead of using the first which has the glyph. This also avoids the issue with punctuation babel seems to have:

\documentclass{article}
\usepackage{fontspec}

\directlua{luaotfload.add_multiscript("noto_greek", 
{
    % Could be: grek = "NotoSerif:mode=base;color=FF8800", as in your example, but especially for Polytonic Greek the language and script should always be set and `mode=base` is except for math fonts almost always a bad choice.
    grek = "NotoSerif:mode=node;color=FF8800;script=grek;language=PGR",
})}

\setmainfont{Source Serif Pro}
[RawFeature={multiscript=noto_greek;color=A0A0A0}]
\setsansfont{Source Sans Pro}

\begin{document}
\section*{Some Polytonic Greek}
\setlength\parindent{0pt}
\setlength\parskip{1.5ex}

Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα,  ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον.

\sffamily
As you can see, \emph{Source Serif Pro} (grey) contains some, but not 
all required glyphs, which are then pulled from my fallback 
font \emph{Noto Serif} (orange). I'd like all Greek characters to be 
taken from Noto Serif (i.e., be orange in this example.)

\end{document}

enter image description here

1
  • Thank you very much for this example (and the comment in the source). Unfortunately, I can only accept one answer, so an upvote will have to do ;-)
    – Ingmar
    Jun 20, 2022 at 17:06

You must log in to answer this question.

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