7

I'm working with a document in English and Hebrew (using polyglossia), and am trying to add hyphenation in Hebrew wherever a hyphen might be. Based on other questions/answers on this site, I have tried to use hyphenat to replace all my hyphens in Hebrew that I would like to be hyphenatable with \hyp{}, but it refuses to hyphenate. See the minimal example below. Manually adding hyphenation rules for individual words is impractical, as I will will have thousands of words to input. Is there a way of forcing LaTeX to allow hyphenation even on the Hebrew side whenever it sees \hyp{} (or even better, an arbitrary character, for example the Hebrew version of the hyphen, U+05BE ־)?

\documentclass[10pt]{book}
\usepackage{polyglossia,hyphenat}

\setdefaultlanguage{english}
\setotherlanguages{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Arial Unicode MS}

\newcommand{\h}[1]{\RL{\texthebrew{#1}\hfil}}
\newcommand{\hangparagentry}{\hangindent-0.5em \hangafter1 \leftskip 0.8em \parindent -0.5em}
\DeclareDocumentCommand{\entry}{ m o m }{\noindent\hangparagentry{\hspace{-.5em}\textbf{#1}\hspace{0.5cm}\hfill \h{#3\IfNoValueF{#2}{ \textenglish{\scriptsize{#2}}}}}\par}

\begin{document}

\flushright

\entry{earthquake meter earthquake meter earthquake meter}{דער ע֜רד\hyp{}צי֜טערניש\hyp{}מע֜סטער, \hyp{}ס}

\end{document}
  • I thought Hebrew is not hyphenated (except in newspapers). However, \- should work – egreg Feb 22 '15 at 23:08
  • @egreg it's actually in Yiddish, but all the code reads "hebrew", so I didn't feel like confusing things. Also, I need the hyphen (or better yet maqqaf) to be there regardless of the word being split over multiple lines or not, hence my use of \hyp. – magicker72 Feb 22 '15 at 23:22
  • You may try with \newcommand\hyp{\discretionary{<maqqaf>}{}{}} (where <maqqaf> is code to produce the glyph; sorry, but I know nothing about Hebrew or Yiddish). Leave a space after \hyp, not {}. – egreg Feb 22 '15 at 23:41
  • 1
    Remove hyphenat. Also \hfill in the definition of \entry is responsible for missing hyphenation: this picture shows what I get when I change it to a simple space – egreg Feb 23 '15 at 0:13
  • 1
    @Florian That's an interesting problem, but probably it requires extensive research and development. – egreg Oct 27 '15 at 16:41
4

Remove hyphenat, to begin with. You could define \hyp to do \discretionary{-}{}{} if you want a discretionary hyphen, but this would be the same as using \-.

If you want a “breakable at” hyphen, just use a hyphen.

\documentclass[10pt]{book}
\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguages{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Arial Unicode MS}

\newcommand{\h}[1]{\RL{\texthebrew{#1}\hfil}}
\newcommand{\hangparagentry}{\hangindent-0.5em \hangafter1 \leftskip 0.8em \parindent -0.5em}

\DeclareDocumentCommand{\entry}{ m o m }{%
  \noindent\hangparagentry{\hspace{-.5em}\textbf{#1}\hspace{0.5cm} %\hfill
  \h{\hspace{0pt}#3\IfNoValueF{#2}{ \textenglish{\scriptsize{#2}}}}}\par}

\begin{document}

\flushright

\entry{earthquake meter earthquake meter earthquake meter}{דער ע֜רד-צי֜טערניש-מע֜סטער, -ס}

\parbox{0pt}{\h{\hspace{0pt}דער ע֜רד-צי֜טערניש-מע֜סטער, -ס}}

\end{document}

The \parbox at the end is just for showing that hyphens are good line break points.

Note that I changed \hfill in the definition of \entry to a simple space. Using \hfill makes TeX into thinking that it's better not to hyphenate in order to get a better paragraph.

enter image description here

  • If I left it as \hfil, would I still prevent hyphenation? I would like to avoid undue spacing between words. – magicker72 Feb 23 '15 at 11:20
  • @magicker72 It depends on several factors; too much stretch available will make TeX prefer not hyphenating. Use \hspace{2em plus 2em} or so instead of \hfill. – egreg Feb 23 '15 at 12:04
  • I've just noticed that your solution has issues outside the \entry environment. Specifically, see the edit to the question. – magicker72 Oct 27 '15 at 16:06
  • @magicker72 It shouldn't be an edit, but a new (follow up) question. – egreg Oct 27 '15 at 16:30
  • 1
    If you want the maqaf instead of the Latin hyphen, you can use \hebrewfont[HyphenChar="5BE,Script=Hebrew]{YourFont} and then replace the hyphens in your source by maqafs. – Florian Oct 27 '15 at 19:35

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.