[Tex/LaTex] Xelatex polyglossia hyphenation

boxeshyphenationline-breakingpolyglossiaxetex

Is there a way to make the polyglossia package solve the hyphenation problem that presents itself in the log as "Overfull \hbox" automatically?

(Note: I find that having shorter lines—even for the entirety of the text—is much less worse than having protruding lines.)

I'm trying to get:

... end of line
end of line
... end of line
... end of line

…but what I have (and don't want) is:

... end of line
... overfullboxishere
... end of line
... end of line

Here's an example of an "overfull box" error:

Example of "overfull box" error #1

Another question: that could be related: polyglossia does not make hyphenation for other specified languages.

Example of "overfull box" error of other language with polyglossia:

Example of "overfull box" error #2

When I use the \textenglish command, the problem seems to solve itself:

\textenglish command is used

However, the resulting document is contaminated with \textenglish, and I don't want \textenglish in my document.

MWE

\documentclass[12pt]{article}

\usepackage{polyglossia}
\usepackage{lipsum}

\setdefaultlanguage{russian}
\setotherlanguages{english}
\setmainfont[Mapping=tex-text]{Times New Roman}

\begin{document}
\lipsum[1]

\begin{itemize}
  \item Возможность работать с такими популярными как
  %  \textenglish{
    MySQL, SQLite, PostgreSQL, Oracle, and Microsoft SQL Server.
  %}
\end{itemize}

\lipsum[1]
\end{document}

Best Answer

In my opinion, the best strategy is still marking the parts in English as such. However, if your English words are just a few, there are alternative approaches.

With ucharclasses

Define transitions to and from Latin characters.

\documentclass[12pt]{article}

\usepackage{polyglossia}
\usepackage{ucharclasses}
\usepackage{microtype} % better management of overfulls

\setdefaultlanguage{russian}
\setotherlanguages{english}
\setmainfont[Ligatures=TeX]{Times New Roman}

\setTransitionsForLatin{\begingroup\hyphenrules{english}}{\endgroup}

\begin{document}

\begin{itemize}
  \item Возможность работать с такими популярными как
    MySQL, SQLite, PostgreSQL, Oracle, and Microsoft SQL Server.

  \item Возможность работать с такими популярными как
  Возможность работать с такими популярными как
  Возможность работать с такими популярными как
\end{itemize}

\end{document}

With just Polyglossia

Define a set of hyphenation rules for the small number of words you need

\documentclass[12pt]{article}

\usepackage{polyglossia}
\usepackage{microtype} % better management of overfulls

\setdefaultlanguage{russian}
\setmainfont[Ligatures=TeX]{Times New Roman}

\begin{hyphenrules}{russian}
\hyphenation{post-gresql or-a-cle mi-cro-soft}
\end{hyphenrules}

\begin{document}

\begin{itemize}
  \item Возможность работать с такими популярными как
    MySQL, SQLite, PostgreSQL, Oracle, and Microsoft SQL Server.

  \item Возможность работать с такими популярными как
  Возможность работать с такими популярными как
  Возможность работать с такими популярными как
\end{itemize}

\lipsum[1]
\end{document}

enter image description here

The output is the same with the two methods. This still produces a small overfull box, but just 0.8pt, but there's not much to do about this apart from rewording.

Note that the ucharclass method is quite heavy, so using it for longer passages in English can slow down processing the file.