28

I have noticed some cases of poor hyphenation in my document. Specifically, LaTeX is breaking hyphenated words like "large-scale" somewhere other than the hyphen. (I thought that this was something that LaTeX famously refuses to do!)

So far I've noticed the problem only in inline lists produced with the enumitem package. Perhaps this is just a coincidence, but I never see the problem in similarly worded text that doesn't use inline lists. Here's a minimal example:

\documentclass[a4paper,11pt]{article}
\usepackage[inline]{enumitem}
\begin{document}
% This paragraph is hyphenated correctly
Foo bar f:
(i)~Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.

% This paragraph is hyphenated poorly
Foo bar f:
\begin{enumerate*}[label=(\roman*)]
\item Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.
\end{enumerate*}
\end{document}

Output:

Output of the above code, showing a strange "large-s-cale" linebreak

What's going on here? Is it enumitem that is at fault? Regardless, is there any way of fixing it? I tried changing large-scale to \mbox{large}-\mbox{scale} but LaTeX refuses to break the line at the hyphen. (In any case, I would prefer a global solution rather than one that requires me to manually locate and fix every mishyphenated word.)

4
  • 3
    Interesting question. I can reproduce this problem when compiling the above with pdflatex or xelatex, but not with lualatex. (That is, LuaTeX, unlike XeTeX and pdfTeX, seems to hyphenate correctly, and not have this problem… in a way it's a shame, as I was hoping LuaTeX callbacks may be useful for peeking into the internal data-structures and seeing what's going on.) Commented Feb 12, 2018 at 20:25
  • Inline enumerations are hard to read and hard to recognize. I wouldn't use them at all, regardless whether done with enumitem or any other package or the manual way
    – user31729
    Commented Feb 12, 2018 at 21:37
  • @ChristianHupfer Well, even Knuth uses them in The TeXbook: in texbook.tex there are 32 instances of (1)~ (inline enumerations done manually). (Corresponding to pages 10, 27, 34, 39, 60, 80, 81, …, 403, 454 of The TeXbook.) (I doubt he uses them in TAOCP though, because there equations have labels, and so using something like “(1)” in a paragraph can be misleading as it usually means a reference to Equation 1.) Commented Feb 12, 2018 at 22:10
  • @ShreevatsaR: Yes, but it still does not look nice ;-)
    – user31729
    Commented Feb 13, 2018 at 4:35

1 Answer 1

23

It is due to the fact that enumerate* boxes the contents and then does \unhbox. No wonder it doesn't happen with XeLaTeX (with nonlegacy fonts) and LuaLaTeX.

\documentclass[a4paper,11pt]{article}
\usepackage[inline]{enumitem}

\begin{document}

% This paragraph is hyphenated correctly
Foo bar f:
(i)~Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.

% This paragraph is hyphenated poorly
Foo bar f:
\begin{enumerate*}[label=(\roman*)]
\item Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.
\end{enumerate*}

% This paragraph is hyphenated poorly
\setbox0=\hbox{Foo bar f:
(i)~Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.}
\leavevmode\unhbox0

\end{document}

enter image description here

Boxing text loses the reference to the current language and mysterious things can happen. Use mode=unboxed.

\documentclass[a4paper,11pt]{article}
\usepackage[inline]{enumitem}

\begin{document}

% This paragraph is hyphenated correctly
Foo bar f:
(i)~Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.

% This paragraph is hyphenated poorly
Foo bar f:
\begin{enumerate*}[label=(\roman*),mode=unboxed]
\item Foo bar foo bar foo bar foo foo bar foo bar foo bar large-scale foo bar foo bar.
\end{enumerate*}

\end{document}

enter image description here

Another example:

\documentclass[twocolumn]{article}

\begin{document}
\parbox{0pt}{\hspace{0pt}supercalifragilistic-expialidocious test}

\vfill\eject

\setbox0=\hbox{supercalifragilistic-expialidocious}
\parbox{0pt}{\hskip0pt\unhbox0\relax\space test}

\end{document}

enter image description here

6
  • Great!!!! +1 for your amazing answer.
    – Sebastiano
    Commented Feb 12, 2018 at 21:48
  • 2
    Thanks, am not the OP, but natural follow-up questions: Why does \unhbox result in these poor hyphenations? Why does enumitem do things this way? Is there anything better about mode=boxed, as reason why mode=unboxed is not the default (or even only) option? Commented Feb 12, 2018 at 21:50
  • 2
    @ShreevatsaR The boxed mode allows for itemjoin*. Boxing text and unboxing it has been a weak point of TeX since the beginning.
    – egreg
    Commented Feb 12, 2018 at 21:59
  • 1
    Thank you, the itemjoin* explains the need for boxed (though I guess it may still make sense to use unboxed by default, and print the warning asking to use boxed when itemjoin* is requested). Separately, I've been trying to reproduce the \setbox0=\hbox … \unhbox0 example in plain TeX (to understand it better), but not quite able to get the line-break after the s: is there some trick that happens in LaTeX that I'm missing? Commented Feb 12, 2018 at 23:05
  • 2
    I especially like how TeX threw in a hyphen after tic- to make it tic-- and thus give an en dash in the right-hand output.
    – Jan
    Commented Feb 13, 2018 at 6:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .