1

If I set the default language to, lets say, english, and as another language greek, I can not get polyglossia (i.e. fontspec in the end?) to use the greek font family I set in my xetex code (with \newfontfamily\greekfont) when compiling with xelatex. If I set the default language to greek, and the other one english, it works.

My M(not)WE is the following. Here, I set the greekfont to Liberation Sans and the greekfontsf to Liberation Serif, just to show that it ignores those definitions. It renders the normal greek (serif) part in serif, and the sans serif part in sans, like this:

enter image description here

\documentclass{article}

\usepackage{polyglossia}

\setmainfont{Liberation Serif}
\setsansfont{Liberation Sans}
\newfontfamily\greekfont{Liberation Sans}
\newfontfamily\greekfontsf{Liberation Serif}
\setdefaultlanguage{english}
\setotherlanguage{greek}

\begin{document}
\tableofcontents{}

\section{Αυτό είναι ελληνικά.}
Welcome to Greek should-not-be-serif: Αυτό είναι ελληνικά

Welcome to Greek should-not-be-sans: \textsf{Αυτό είναι ελληνικά}

Another try to should-not-be-sans: \textgreek{\textsf{Αυτό είναι ελληνικά}}
\end{document}

If one now sets \setdefaultlanguage{greek} and \setotherlanguage{english}, it does select the correct font shapes:

enter image description here

What is going on? Unfortunately, other similar questions didnt help. Specifically, this one seemed to be very relevant. But it didnt work :/

//UPDATE: Since the scope of this question is answered, I was able to refine what the problem actually is. Thus, I opened another question found here.

hintze
  • 145
  • try this: \textgreek{\textsf{Αυτό είναι ελληνικά}} – Yorgos Jan 16 '17 at 20:31
  • Thank you for your suggestion @Yorgos, but the result looks the same as without \textgreek, it doesnt work. May I ask whether my MWE produces a PDF with correct fonts selected in your tex setup? – hintze Jan 16 '17 at 20:33
  • i compiled your mwe with no problem. Liberation Sans works for greek language – Yorgos Jan 16 '17 at 20:43
  • thanks for clarification. but, unfortunately, thats not the problem. both, sans and serif, work for greek. but please note how I chose a sans font for serifed greek and vice versa. the greek text in my compiled PDF just does not select the correct font. – hintze Jan 16 '17 at 20:46
  • I understood your problem, but as I said your mwe worked for me. That is, \textsf command works, whereas for the rest of it serif font applies – Yorgos Jan 16 '17 at 20:48
  • haha lol I am so sorry for the confusion. I really appreciate that you take your time to help me, and I kind of sabotage it with being confused. but, now that I see that it could be confusing, I updated my post with a screenshot how it looks like in my PDF output (which is wrong in terms of greek fonts selected) – hintze Jan 16 '17 at 20:58
  • change your setmainfont to Liberation Sans and also remove your definitions (it sounds silly, i know :P). – Yorgos Jan 16 '17 at 21:38
  • the reason for having this problem is that textsf by definition produces the sans serif font and not the serif font – Yorgos Jan 16 '17 at 21:56
  • well, but just setting the main font to something doesnt solve the problem that I would like to specify different fonts for latin and greek script. furthermore, I am fairly sure that \textsf{text} does produce sans serif text, not serifed. – hintze Jan 16 '17 at 22:00
  • sorry but i really do not understand your problem. In my case, I set Liberation Serif as a main font for my whole document (i.e. for both english and greek text). Whatever is inside textsf{} appears in sans serif – Yorgos Jan 16 '17 at 22:04
  • last attempt... try \sffamily{\textgreek{something}} – Yorgos Jan 16 '17 at 23:07
  • this way around worked, with \textit{\textgreek{foo}} it selects the font I set with \newfontfamily\textgreeksf{}. Now the question is much clearer: Why does xelatex not detect greek text on its own? (Or: If it detects it, why does it not choose the correct font?) – hintze Jan 16 '17 at 23:12
  • i believe, because you have specified two different fonts for the same language. thus, maybe xelatex does not know which font (serif or sans) you want to be the default for the greek language – Yorgos Jan 16 '17 at 23:16

1 Answers1

2

Just try to specify firstly your family font and then the greek text. As you can see, in the second case definitions are taking into account, whereas in the third are ignored

\documentclass{article}

\usepackage{polyglossia}

\setmainfont{Liberation Serif}
\setsansfont{Liberation Sans}
\newfontfamily\greekfont{Liberation Sans}
\newfontfamily\greekfontsf{Liberation Serif}
\setdefaultlanguage{english}
\setotherlanguage{greek}

\begin{document}
\tableofcontents{}

\section{Αυτό είναι ελληνικά.}
Welcome to Greek should-not-be-serif: Αυτό είναι ελληνικά

Welcome to Greek should-not-be-sans: \sffamily{\textgreek{Αυτό είναι ελληνικά}}

Another try to should-not-be-sans: \textgreek{\sffamily{Αυτό είναι ελληνικά}}
\end{document}
Yorgos
  • 2,694
  • Since it works within \textgreek{}: Why does xelatex not detect greek text on its own? (Or: If it detects it, why does it not choose the correct font?) Because, for example, if I have a bibliography with greek letters within latin text, I would have to enclose those greek letters in \textgreek in my bib-file. – hintze Jan 16 '17 at 23:14
  • I always use \defaultfontfeaures{Mapping=tex-text} and so xelatex always detect greek characters, without using \textgreek{} command – Yorgos Jan 16 '17 at 23:39
  • Adding \defaultfontfeatures{Mapping=tex-text} to the MWE still produces the same PDF output with xelatex like before. Still, you have kind of solved my problem. Not completely, but in scope of my original post you answered how to get correct font selection by enclosing greek text in \textgreek{}. Since changing my question now to focus on how to let xetex/polyglossia/fontspec select the correct font on its own, I am going to post a new question and add a link here. Thank you. – hintze Jan 17 '17 at 08:55