3

After having some hyphenation problems with my text (in greek and english) I changed some of my packages. In the beggining I was using:

  \usepackage{mathspec} 
  \usepackage{xgreek}
  \usepackage{xunicode}
  \usepackage{fontspec}
  \setallmainfonts[Mapping=tex-text]{Arial}
  \setallsansfonts[Mapping=tex-text]{Arial}
  \setallmonofonts[Mapping=tex-text]{Arial}

After doing some search I modified those to get correct hyphenation. After doing so in a small sample text, I am trying to change the packages of my original text to the ones used in my sample, in order to get finally the correct hyphenation. However at some point I get:

Package polyglossia error: The current Roman Font does not contain the Greek Script.

Line 242: \begin{verbatim}

The packages I use are the following:

\usepackage{fontspec}
\newfontfamily\greekfont[Script=Greek]{Linux Libertine O}
\newfontfamily\greekfontsf[Script=Greek]{Linux Libertine O}
\usepackage[Greek,Latin]{ucharclasses}
\usepackage{polyglossia}
\usepackage{xltxtra}
\setmainlanguage{greek}
\setotherlanguages{english}
\setTransitionsForGreek{\selectlanguage{greek}}{\selectlanguage{english}}
\setmainfont{Linux Libertine O}

How can this be fixed?

  • You have to define also \greekfonttt. I would never use ucharclasses for interspersing English in Greek; you risk many unexpected results. – egreg Oct 16 '12 at 17:21
  • So what would you recommend instead? Apart the strategy when you define a command for change language and then you put the language X block in it, like \en{I am Jonathan} \gr{Είμαι ο Γιάννης} – Paramar Oct 16 '12 at 17:38
  • The default language is Greek; just define \en for English snippets: \newcommand{\en}[1]{\foreignlanguage{english}{#1}} and use the provided environments to switch languages for longer passages in English (and maybe \gr for inserting Greek snippets in English text). Marking the code is always better. One problem you can run into is exactly that \verb text may not be typeset in the mono font. – egreg Oct 16 '12 at 17:45
  • @egreg Make that an answer, please. – lockstep Nov 4 '12 at 15:01
3

Verbatim text uses the font defined with \setmonofont (or the default Latin Modern Typewriter font).

However, when the Greek language is active, Polyglossia makes XeLaTeX look whether the font has the GRK feature and, if that's not available, it looks whether a font family under the name \greekfonttt has been defined. Thus

\newfontfamily{\greekfonttt}{FreeMono}

(use your preferred monospaced font) should do.

I wouldn't use ucharclasses for switching automatically from English to Greek and conversely: this will fill your auxiliary files with \select@language declarations and won't ensure that a monospaced font is used in verbatim. Rather prefer the standard method of confining language switches with explicit \selectlanguage commands (not recommended), otherlanguage, otherlanguage* or \foreignlanguage.

  • Thanks for this answer. Have a question about your remark: Why not use ucharclasses for switching automatically from English to <other language> and back? It seems easier than explicitly writing \textsanskrit (or whatever) at each place the other language is used. – ShreevatsaR Nov 7 '16 at 4:01
  • @ShreevatsaR I think that the last paragraph explains it – egreg Nov 7 '16 at 7:45
  • Thanks, I understand the issue with verbatim: what is not clear to me is whether, in case there is no verbatim used in the document (and thus no need for a monospaced font), it is still the case that "this will fill your auxiliary files with \select@language declarations" has any negative consequences that would discourage using ucharclasses to switch language automatically. – ShreevatsaR Nov 7 '16 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.