3

I'm trying to define different fonts for different scripts, Latin and Greek. I'm currently using Linux Libertine O as my main font, which includes support for Greek, but I would like to try using a different font for Greek. Can I do that without using \newfontfamily\greekfont[Script=Greek,⟨…⟩]{⟨font⟩}, which would require me to use a command \textgreek{} whenever I want to switch fonts? That is, is there a way of switching the fonts automatically whenever the Greek script is used?

I want to change the fonts because of how Libertine handles the circumflex accent using a tilde instead of an inverted breve. The Gentium Plus font allows me choose between the two. I wasn't able to find out if Libertine also has such font featue.

\documentclass{article}
\usepackage{fontspec}

\setmainfont{Linux Libertine O}
\newfontfamily\greekfont[RawFeature=+cv78]{Gentium Plus}

\begin{document}

ῶ \greekfont{ῶ}

\end{document}

enter image description here

4
  • Fonts include typically both scripts: Latin and Greek (Libertine, for example). I don't undesttand why do you need to switch fonts. You can use single font for both.
    – wipet
    Mar 27, 2021 at 16:27
  • with xetex you can use xetexcharclasses, see e.g. tex.stackexchange.com/a/21101/2388, for luatex babel has support to automatically change fonts, Mar 27, 2021 at 16:48
  • @wipet It is because Libertine handles the circumflex accent using a tilde instead of an inverted breve. The Gentium Plus font allows me choose between the two. I wasn't able to find out if Libertine also has such font featue.
    – igm2103
    Mar 27, 2021 at 19:01
  • @UlrikeFischer I have tried the answer given by @pmav99 in tex.stackexchange.com/a/21101/2388, but the fonts for the Greek text were not changed. I have also tried using babel with \babelprovide[import]{ancientgreek} \babelfont[ancientgreek]{rm}[RawFeature=+cv78]{Gentium Plus} but this didn't change the fonts either. It only works if I use a macro such as \selectlanguage to change the language.
    – igm2103
    Mar 27, 2021 at 19:25

2 Answers 2

4

In LuaLaTeX, you can use the features of babel to automatically change fonts to match the script you’re typing in. In this example, the serif font is Libertinus Serif for Latin and Gentium Plus for Greek. The sans-serif letters are in Libertinus Sans (a clone of Linux Biolinum), but have the OpenType script and language feature set to Latin/English or Greek/Greek automatically. This also selects Greek or English hyphenation patterns.

\documentclass[english]{article}
\usepackage{babel}
\usepackage{unicode-math}
\usepackage{microtype}
\usepackage{uninormalize}

\babelprovide[import=el-polyton, onchar=ids fonts]{greek}

\defaultfontfeatures{ Ligatures=TeX,
                      Scale=MatchLowercase }
\babelfont{rm}
          [Ligatures={Common,Rare}, Scale=1.0]{Libertinus Serif}
\babelfont[greek]{rm}
          {Gentium Plus}
\babelfont{sf}
          [Ligatures={Common,Rare}]{Libertinus Sans}
\babelfont{tt}
          {Libertinus Mono}
\setmathfont{Libertinus Math}

\begin{document}

uῶ \textsf{uῶ}

\end{document}

LuaLaTeX font sample

I selected a matching OpenType math font, uninormalize to prevent a bug that could strand naked accents at the start of a new line, and microtype to enable font expansion.

You will get some harmless warning messages about English and Polytonic Greek font features not being available in those fonts. This just means that these fonts do not define any special OpenType features for the Greek language over and above those it defines for the Greek script. You can suppress the warnings by adding the Language=Default option when you load the font, the same way you enable Ligatures=. This is also where you should select Variant=78 (the sugared name for cv78).

In XeLaTeX, you would want to use ucharclasses for this, and have it change the current language rather than select a particular font. This way, it works for serif, sans-serif and monospace, and correctly hyphenates Greek words.

\documentclass[english]{article}
\usepackage{babel}
\usepackage{unicode-math}
\usepackage{ucharclasses}

\babelprovide[import=el-polyton]{greek}

\defaultfontfeatures{ Ligatures=TeX,
                      Scale=MatchLowercase }
\babelfont{rm}
          [Ligatures={Common,Rare}, Scale=1.0]{Libertinus Serif}
\babelfont[greek]{rm}
          {Gentium Plus}
\babelfont{sf}
          [Ligatures={Common,Rare}]{Libertinus Sans}
\babelfont{tt}
          {Libertinus Mono}
\setmathfont{Libertinus Math}

\setDefaultTransitions{\selectlanguage{english}}
                      {\selectlanguage{english}}
\setTransitionTo{GreekAndCoptic}
                {\selectlanguage{greek}}
\setTransitionTo{GreekExtended}
                {\selectlanguage{greek}}

\begin{document}

uῶ \textsf{uῶ}

\end{document}

XeLaTeX sample

1

I found a package that automates the xetexcharclasses approach suggested by @ UlrikeFischer.

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\latinfont}{Linux Libertine O}
\newfontfamily{\greekfont}[RawFeature=+cv78]{Gentium Plus}

\usepackage[Greek, Latin]{ucharclasses}

\setDefaultTransitions{\defaultfont}{}
\setTransitionsForLatin{\latinfont}{}
\setTransitionsForGreek{\greekfont}{}

\begin{document}

This is written in Linux Libertine; the Greek in Gentium Plus.  ῶ

\end{document}

enter image description here

You must log in to answer this question.

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