[Tex/LaTex] How to obtain proper justification with XeLaTeX and fontspec package

babelfontspecgreekpolyglossiaxetex

I'm trying to obtain a justified paragraph with greek text using XeLaTeX and fontspec package, but there is always a word that exceed the right alignment.

Note that with LaTex and the default greek font the given output is correct, with hyphenation, while with XeLaTeX and fontspec (and any greek font) there isn't hyphenation.

\documentclass[12pt]{article}
\usepackage[a4paper,top=2cm,bottom=1cm,left=3cm,right=3cm]{geometry}

\usepackage{fontspec}

\setmainfont{Palatino Linotype}

\usepackage[doublespacing]{setspace}

\setlength\parindent{0pt}


\begin{document}


Ἐν Μεγάροις ἰδὼν τὰ μὲν πρόβατα τοῖς δέρμασιν ἐσκεπασμένα, τοὺς δὲ παῖδας αὐτῶν γυμνούς, ἔφη, “λυσιτελέστερόν ἐστι Μεγαρέως εἶναι κριὸν ἢ υἱόν.” πρὸς τὸν ἐντινάξαντα αὐτῷ δοκόν, εἶτα εἰπόντα, “φύλαξαι,” “πάλιν γάρ με,” ἔφη, “παίειν μέλλεις;” ἔλεγε τοὺς μὲν δημαγωγοὺς ὄχλου διακόνους, τοὺς δὲ στεφάνους δόξης ἐξανθήματα. λύχνον μεθ' ἡμέραν ἅψας, “ἄνθρωπον,” φησί, “ζητῶ.” εἱστήκει ποτὲ κατακρουνιζόμενος· τῶν δὲ περιεστώτων ἐλεούντων, παρὼν Πλάτων ἔφη, “εἰ βούλεσθ' αὐτὸν ἐλεῆσαι, ἀπόστητε,” ἐνδεικνύμενος φιλοδοξίαν αὐτοῦ. ἐντρίψαντος αὐτῷ κόνδυλόν τινος, “Ἡράκλεις,” ἔφη, “οἷον με χρῆμ' ἐλάνθανε  τὸ μετὰ περικεφαλαίας περιπατεῖν.” 

\end{document}

enter image description here

UDPATE:

Although the solution proposed by egreg works good with standard margin, changing the margin dimension will result in a text with overfull lines.
So i used the parameter

\tolerance=10000

following the instructions found here : http://www.tex.ac.uk/cgi-bin/texfaq2html?label=overfull. It seems to work properly:

\documentclass[12pt]{article}
\usepackage[a4paper,top=2cm,bottom=1cm,left=6cm,right=6cm]{geometry}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont[Ligatures=TeX]{Palatino Linotype}
\setmainlanguage[variant=polytonic]{greek}

\setlength\parindent{0pt}
\tolerance=10000

\begin{document}

Ἐν Μεγάροις ἰδὼν τὰ μὲν πρόβατα τοῖς  δέρμασιν ἐσκεπασμένα, τοὺς δὲ παῖδας αὐτῶν 
υμνούς,  ἔφη, “λυσιτελέστερόν ἐστι Μεγαρέως  εἶναι  κρι-ὸν ἢ υἱόν.” πρὸς τὸν ἐντινάξαντα 
αὐτῷ δοκόν, εἶτα εἰπόντα, “φύλαξαι,” “πάλιν γάρ με,” ἔφη,  “παίειν μέλλεις;” ἔλεγε τοὺς 
μὲν δημαγωγοὺς ὄχλου διακόνους, τοὺς δὲ στεφάνους δόξης ἐξανθήματα. λύχνον μεθ' ἡμέραν 
ἅψας,  “ἄνθρωπον,”   φησί, “ζητῶ.” εἱστήκει ποτὲ κατακρουνιζόμενος· τῶν δὲ περιεστώτων  
ἐλεούντων, παρὼν Πλάτων ἔφη, “εἰ βούλεσθ' αὐτὸν ἐλεῆσαι, ἀπόστητε,” ἐνδεικνύμενος 
φιλοδοξίαν αὐτοῦ. ἐντρίψαντος αὐτῷ κόνδυλόν τινος, “Ἡράκλεις,” ἔφη, “οἷον με χρῆμ' 
ἐλάνθανε τὸ μετὰ περικεφαλαίας περιπατεῖν.” 

\end{document}

enter image description here

Best Answer

I don't have the “Palatino Linotype” font, so I use a substitute, which requires the definition of \greekfont (one gets a suitable warning, in case this is necessary).

\documentclass[12pt]{article}
\usepackage[a4paper,top=2cm,bottom=1cm,left=3cm,right=3cm]{geometry}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont[Ligatures=TeX]{Palatino}
\setmainlanguage[variant=polytonic]{greek}
\newfontfamily{\greekfont}[Ligatures=TeX]{Palatino}

\begin{document}


Ἐν Μεγάροις ἰδὼν τὰ μὲν πρόβατα τοῖς δέρμασιν ἐσκεπασμένα, τοὺς δὲ
παῖδας αὐτῶν γυμνούς, ἔφη, “λυσιτελέστερόν ἐστι Μεγαρέως εἶναι κριὸν ἢ
υἱόν.” πρὸς τὸν ἐντινάξαντα αὐτῷ δοκόν, εἶτα εἰπόντα, “φύλαξαι,” “πάλιν
γάρ με,” ἔφη, “παίειν μέλλεις;” ἔλεγε τοὺς μὲν δημαγωγοὺς ὄχλου διακόνους,
τοὺς δὲ στεφάνους δόξης ἐξανθήματα. λύχνον μεθ' ἡμέραν ἅψας, “ἄνθρωπον,”
φησί, “ζητῶ.” εἱστήκει ποτὲ κατακρουνιζόμενος· τῶν δὲ περιεστώτων
ἐλεούντων, παρὼν Πλάτων ἔφη, “εἰ βούλεσθ' αὐτὸν ἐλεῆσαι, ἀπόστητε,” 
ἐνδεικνύμενος φιλοδοξίαν αὐτοῦ. ἐντρίψαντος αὐτῷ κόνδυλόν τινος,
“Ἡράκλεις,” ἔφη, “οἷον με χρῆμ' ἐλάνθανε τὸ μετὰ περικεφαλαίας
περιπατεῖν.”

\end{document}

enter image description here

As you see there's no overfull line with words sticking into the margin and hyphenation is properly done.

Install a full TeX distribution, either TeX Live 2013 or MiKTeX 2.9 if on Windows, but I recommend TeX Live anyway.

For GNU/Linux systems, see the TUG page and several questions on this site.

Related Question