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

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • 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 '22 at 06: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 '22 at 06: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 '22 at 07: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 '22 at 08:07
  • polyglossia catches glyphs and punctuation, but needs \selectlanguage{greek} switches, so not automatic. – Cicada Jun 19 '22 at 08:27
  • The Babel approach is very close to what I am looking for. Color doesn't work (but is only for debugging anyway), and I do get a fontspec warning (Language 'Greek' not available for font 'NotoSerif' with script 'Greek') but despite that, it appears to work. Would you care to convert your comment to an answer? – Ingmar Jun 19 '22 at 09:43
  • Update: Color had to be provided in hex triplet form, i.e. [Colour=FF8800] (I didn't load xcolor). – Ingmar Jun 19 '22 at 09:47
  • This is a quite interesting problem, which cannot be solved in a general way. Consider the following sentence:: “Οὐχὶ, ταὐτὰ, and παρίσταταί are the first words in this text.” In this case the punctuation font must be the English one. There is no way to know the correct font in an unmarked text. (Several criteria are possible, like the first letter in the paragraph or the surrounding letters, but even so manual switching can be still necessary.) With babel you can use both implicit and explicit font/language switching. – Javier Bezos Jun 20 '22 at 16:21

2 Answers2

7

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

  • 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 '22 at 17:06
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}

Cicada
  • 10,129
  • 1
    Of course, manual switching is available in babel, too. – Javier Bezos Jun 20 '22 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 '22 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 '22 at 06:39