1

How do I avoid the hyphenation ladder effect in XeLaTeX?

Consider the following as an example...

I want to hyphe-

nate this senten-

ce, but the pre-

sence of quadru-

ple lines suc-

cessively hyphe-

nated or even more than that, is just too much for my poor eyes.

McGafter
  • 2,266
  • If you're typesetting in narrow columns, hyphens are unavoidable. – egreg Dec 03 '14 at 13:16
  • If you don't want to hyphenate you have to allow latex do do something instead, eg \raggedright – David Carlisle Dec 03 '14 at 13:18
  • @McGafter Maybe you can switch to LuaLaTeX and try \usepackage{microtype}. You might be lucky with this. – LaRiFaRi Dec 03 '14 at 13:36
  • 1
    you could try increasing the value of \doublehyphendemerits. in knuth's gkpmac.tex, it's set to 100000; latex sets it to only 10000. but the suggestion to use microtype is a good one; it should work with pdflatex as well. – barbara beeton Dec 03 '14 at 13:43
  • The idea is to allow hyphens, but to reduce them to 3 subsequent ones at the most. – McGafter Dec 03 '14 at 15:03
  • 1
    Have you modified the value of \righthyphenmin? The reason I ask is that you report the hyphenation point senten-ce occurring. This is not only wrong, it can only happen if you or one of the packages you load have modified the parameter \righthyphenmin. – Mico Dec 03 '14 at 16:03
  • @Mico That was just an example to show the ladder effect. Not an actual case produced by my code. So I was just asking for a very broad general solution. – McGafter Dec 04 '14 at 09:11
  • @McGafter What you are asking sounds really difficult. I can't imagine a case, where microtype or \RaggedRight will not do the trick. Please show some real use-case! If you want to count the number of hyphens at line ends, this would need some real scripting (probably easiest in Lua). If you have columns that narrow, you should redesign your table or what ever construct you have. – LaRiFaRi Dec 04 '14 at 11:57
  • @LaRiFaRi I'll accept your answer down below, since I know it's a difficult problem, but I thought it has been addressed in the past perhaps. My other typesetting software like Serif Page Plus can be set to allow only a certain amount of hyphenated lines directly after each other. Anyway your solution is the quickest and cleanest to implement in my script. So thanks. – McGafter Dec 04 '14 at 12:11
  • @McGafter You are welcome. What does Serif Page Plus do, if it reaches your given limit? – LaRiFaRi Dec 04 '14 at 12:14
  • @LaRiFaRi I don't know what it does but the effect is that it probably mess about with the kerning etc. so that the following line after your preset amount of hyphenated lines, are not hyphenated. It does not necessarily always look well spaced out, but you at least don't get a 'ladder' effect going for six or seven lines. http://www.serif.com/appresources/PPX6/Tutorials/en-gb/help/inserting_a_hyphen.htm – McGafter Dec 04 '14 at 15:17

2 Answers2

4

enter image description here

The only way I could get that many hyphens in that text is to force tex to prefer them, this shows various alternative settings

\documentclass{article}
\usepackage{ragged2e}
\begin{document}

\def\t{I want to hyphenate this sentence, but the presence of quadruple lines successively hyphenated}

\noindent\mbox{\vrule\ 
\begin{minipage}[t]{3.1cm}
 \hyphenpenalty=-500
\t
\end{minipage}\ \vrule\
\begin{minipage}[t]{3.1cm}
 %\hyphenpenalty=-500
\t
\end{minipage}\ \vrule\
\begin{minipage}[t]{3.1cm}
\raggedright
\t
\end{minipage}\ \vrule\
\begin{minipage}[t]{3.1cm}
\RaggedRight
\t
\end{minipage}\ \vrule}

\end{document}
David Carlisle
  • 757,742
3

Just load microtype and see, if it helps:

% xelatex

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setlength{\textwidth}{6.3em}
\setlength{\parindent}{0em}
%\usepackage{microtype}

\begin{document}
I want to hyphenate this sentence, but the presence of quadruple lines successively hyphenated
\end{document}

Without:

enter image description here

With:

enter image description here

LaRiFaRi
  • 43,807