3

In the following example

\documentclass{article}
\usepackage{polski}

\begin{document}

\hyphenation{Bor-zo-bo-ha-ta}

\begin{tabular}{|p{6mm}|} Bor-zo-bo-ha-ta\ Borzobohata \end{tabular} \end{document}

(La)TeX ignores patterns set by \hyphenation. Why?

enter image description here

The vertical lines show the horizontal space.

  • 3
    If you remove the \\ it works ok. Compiling with LuaLaTeX works ok also. It is puzzling, yes. – yannisl Nov 14 '23 at 05:24

1 Answers1

7

pdfTeX and XeTeX -- but not LuaTeX -- possess the following feature/bug: The very first word in a (syntactic) paragraph does not get hyphenated. In TeX syntax, a "paragraph" is of fundamental importance. Lots and lots of things are paragraphs to TeX, including the cells in a table that are formatted as a p-type column.

The fix? Either employ Lua(La)TeX or be sure to load the array package and to change p{7mm} to >{\hspace{0pt}}p{7mm}. That way, as far as TeX is concerned, "Borzobohata" (or any other word, for that matter) is no longer the very first "object" in the cell, allowing it to be hyphenated.

enter image description here

% !TEX TS-program = pdflatex
\documentclass{article}
\usepackage{polski} % is it better to use '\usepackage[polish]{babel}'?
\usepackage{array}

\hyphenation{Bor-zo-bo-ha-ta}

\begin{document}

\begin{tabular}{ | >{\hspace{0pt}}p{1sp} } Borzobohata \end{tabular}

\end{document}

Mico
  • 506,678
  • 2
    Good to know. I have been using LuaTeX exclusively for the last 5 years or so and could not be happier. One more reason to recommend to people to use it. As an aside, initially I thought maybe the problem was the polski package. How can one load patterns in LuaTeX without Babel or Polyglossia? – yannisl Nov 14 '23 at 07:02
  • 1
    @YiannisLazarides - Does \hyphenation{Bor-zo-bo-ha-ta} work for you? – Mico Nov 14 '23 at 07:05
  • Yes it did with LuaLaTeX – yannisl Nov 14 '23 at 07:15
  • 1
    It also gives reasonable hyphenation even without the \hyphenation – yannisl Nov 14 '23 at 07:17
  • 1
    Thank you! Is this, say, feature documented in The TeXbook? – Przemysław Scherwentke Nov 14 '23 at 15:21
  • 1
    @PrzemysławScherwentke - For me, a passage in the TeXbook that comes close to qualifying as making the inability to hyphenate the first word in a paragraph a "documented feature" occurs in Appendix H, "Hyphenation", in the 2nd paragraph on p. 454: "TeX looks for potentially hyphenatable words by searching ahead from each glue item..." This condition excludes the first word in a paragraph, as a paragraph does not (usually) start with "glue" (TeX jargon alert). By prefixing \hspace{0pt} -- a somewhat special form of glue! -- to the cell, the first word in the cell is made hyphenatable. :-) – Mico Nov 14 '23 at 15:53