5

When using polyglossia to hyphenate my Turkish documents, I frequently have issues with very long words on short lines. I need it to be more aggressive about hyphenation wherever it can be. One obvious case that is regularly as issue is proper names with large numbers of suffixes. The suffixes in the case of proper names are set apart from the work with an apostrophe. Unfortunately polyglossia stops looking for ways to hyphenate after that.

Here is an MWE showing how a base word ges hyphenated and how it's seen after adding a couple suffixes:

\documentclass{minimal}
\usepackage{polyglossia}
\usepackage{testhyphens}
\setmainlanguage{turkish}
\begin{document}
\begin{checkhyphens}{}
İstanbullularınki
İstanbul'lularınki
\end{checkhyphens}
\end{document}

MWE Output

I would like this to result in İs-tan-bul'lu-la-rın-ki instead, not hyphenating at the first syllable after the start of suffixes, but continuing as normal thereafter. Is there a way to re-enable evaluation of normal hyphenation rules after such breaks document-wide?

  • Do you run XeLaTeX or LuaLaTeX? Which TeX distribution do you have: TeXlive, MikTeX, or something else? Which version of the polyglossia package do you have? (The version that's distributed with MacTeX2014 is v1.33.5, dated 2014/05/21. When I run your MWE on my system, I do not encounter the problem you report getting.) – Mico Mar 23 '15 at 13:38
  • @Mico Interesting. I'm using Texlive + XeLaTeX, and my polyglossia package appears to be the same as yours: 2014/05/21 v1.33.5. – Caleb Mar 23 '15 at 13:47
  • 1
    lualatex hyphenates the works as wanted, so it is an engine problem. – Ulrike Fischer Mar 23 '15 at 13:49
  • Aah, I should have mentioned that I ran your MWE under LuaLaTeX only (and didn't get an error). – Mico Mar 23 '15 at 13:55
  • @UlrikeFischer Ug. I switched from lualatex specifically because it had some other issues with ligatures that is was not handling correctly. So I guess this question becomes---how do I fix xelatex? – Caleb Mar 23 '15 at 13:55
5

If I try the “proper” way, that is, making the apostrophe a letter as far as hyphenation is concerned, I get

İs-tan-bu-l-’-lu-la-rın-ki

because the patterns allow hyphens at either side of a consonant except for some specific combinations, which don't take the apostrophe into consideration. Perhaps you would consider making a feature request at the TeX-hyphen mailing list.

The “proper” way would be to set, for Turkish, \lccode"2019="2019 (which is the magic making the apostrophe to be considered for hyphenation).

One has to resort to babel style shorthands:

\documentclass{article}
\usepackage{polyglossia}
\usepackage{testhyphens}

\setmainlanguage{turkish}

\makeatletter
\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{'}%
}{}
\def\turkish@shorthands{%
  \bbl@activate{'}%
  \def\language@group{turkish}%
  \declare@shorthand{turkish}{'}{\turkish@apostrophe}%
}
\def\noturkish@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{'}}%
}
\define@boolkey{turkish}[turkish@]{babelshorthands}[true]{}
\setkeys{turkish}{babelshorthands=true}
\appto\blockextras@turkish{\ifturkish@babelshorthands\turkish@shorthands\fi}
\appto\inlineextras@turkish{\ifturkish@babelshorthands\turkish@shorthands\fi}
\appto\noextras@turkish{\noturkish@shorthands}
\newcommand\turkish@apostrophe{\@ifnextchar'{”\@gobble}{’\hspace{0pt}}}
\makeatother

\begin{document}

\begin{checkhyphens}{}
İstanbullularınki
İstanbul'lularınki
\end{checkhyphens}

Double quotes are OK: \fbox{''}

\end{document}

enter image description here

This allows a line break after the apostrophe; if you don't want it, then use

\nobreak\hspace{0pt}

Note that this doesn't affect the “real” apostrophe (it can't be used as a shorthand). If you are using in your document, then you can exploit \newunicodechar:

\documentclass{article}
\usepackage{polyglossia}
\usepackage{testhyphens}

\setmainlanguage{turkish}

\makeatletter
\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{'}%
}{}
\def\turkish@shorthands{%
  \bbl@activate{'}%
  \def\language@group{turkish}%
  \declare@shorthand{turkish}{'}{\turkish@apostrophe}%
}
\def\noturkish@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{'}}%
}
\define@boolkey{turkish}[turkish@]{babelshorthands}[true]{}
\setkeys{turkish}{babelshorthands=true}
\appto\blockextras@turkish{\ifturkish@babelshorthands\turkish@shorthands\fi}
\appto\inlineextras@turkish{\ifturkish@babelshorthands\turkish@shorthands\fi}
\appto\noextras@turkish{\noturkish@shorthands}
\newcommand\turkish@apostrophe{\@ifnextchar'{”\@gobble}{\string’\hspace{0pt}}}
\makeatother

\usepackage{newunicodechar}
\newunicodechar{’}{'}

\begin{document}

\begin{checkhyphens}{}
İstanbullularınki
İstanbul'lularınki
İstanbul’lularınki
\end{checkhyphens}

Double quotes are OK: \fbox{''}

\end{document}

enter image description here

| improve this answer | |
  • could you please expand on that "magic" part? Because yeah, a lot of times some lines in LaTeX look like incantations of some arcane magic, but I'd like to understand and the classification as "magic" is detrimental to that cause ;) .... thanks. – 0xC0000022L Jul 3 '19 at 11:37
  • @0xC0000022L The magic \lccode"2019="2019 makes the apostrophe considered for hyphenation: only characters with nonzero \lccode are considered; "2019 is the (Unicode) character code for the apostrophe. – egreg Jul 3 '19 at 11:48
  • Thank you very much for the explanation! – 0xC0000022L Jul 3 '19 at 11:58

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.