15

For the following example,

\hsize =2in

shelf{}ful shelf{}ful shelf{}ful
rot{}ten rot{}ten
shelf{}ful shelf{}ful shelf{}ful

shelf{}ful shelf{}ful
rot{}ten rot{}ten
shelf{}ful shelf{}ful

\bye

The result is as followings:

enter image description here

My questions is: in the first paragraph, why the first shelfful is without ligature, but the other shelfful are with ligatures?

yo'
  • 51,322
Z.H.
  • 3,346
  • 21
  • 39
  • 3
    TeX doesn't hyphenate the first word of a paragraph. – Ulrike Fischer Oct 28 '14 at 10:00
  • @UlrikeFischer What does that mean? A little more info would be welcome. – Manuel Oct 28 '14 at 10:04
  • @Manuel: It means what it says: The braces are obviously lost when TeX tries to find hyphenation points which it doesn't do on the first work of a paragraph. – Ulrike Fischer Oct 28 '14 at 10:10
  • @UlrikeFischer Mmm… I don't get it. There are two paragraphs, and only in the first one all but the first {} seem to do nothing, since the ff are ligatured. – Manuel Oct 28 '14 at 10:15
  • @Manuel: the second paragraph has no hyphenation at all. TeX was able to set it without having to find hyphenation points. – Ulrike Fischer Oct 28 '14 at 10:21
  • 6
    The TeXBook (TeX3 version, not TeX2 edition) explicitly warns against using {} to break ligatures for precisely this reason, the {} is lost if the word is reconstituted after a hyphenation trial. – David Carlisle Oct 28 '14 at 10:25
  • @UlrikeFischer Understood (better with the comment of David :P). – Manuel Oct 28 '14 at 10:27

1 Answers1

19

The TeXBook has this exercise:

exercise Sometimes you run into a rare word like 'shelfful' that looks better as shelf{}ful without the ff ligature. How can you fool TeX into thinking that there aren't two consecutive f's in such a word?

answer {shelf}ful or shelf{}ful, etc.; or even shelf\/ful, which yields a shelf/ful instead of a shelf{\kern0pt}ful. In fact, the latter idea---to insert an italic correction---is preferable because TeX will ^reinsert the ff ligature by itself after hyphenating shelf{}ful. Appendix H points out that ligatures are put into a hyphenated word that contains no explicit kerns, and an italic correction is an explicit kern.) But the italic correction may be too much (especially in an italic font); shelf{\kern0pt}ful is often best.

Note here that "after hyphenating" should be read as "after trying to hyphenate" If TeX attempts to hyphenate a word it essentially splits it up at the possible break points to add discretionary hyphens. If then hyphenation is not used at that point the word is reconstituted without those hyphenation points, but the original {} information is lost by then and ligatures will be formed in the reconstituted word.

TeX (not luatex) never attempts to hyphenate the first word of a paragraph (essentially a bug that was classified as a feature to keep TeX stable) and also it does not attempt to hyphenate any words in a paragraph if it can break the paragraph into lines and keep within \pretolerance badness. So whether f{}f actually breaks an ff ligature is rather variable depending on the whole paragraph, not just the word where {} is used.

David Carlisle
  • 757,742
  • 2
    Even more important not to use {} when LuaTeX is involved, as it deliberately doesn't follow the same approach as 'classical' TeX (but there are Lua-based ways to suppress ligatures in defined words). – Joseph Wright Oct 28 '14 at 10:35
  • Actually the question does come from my reading of this exercise of the TeXbook. I think after hyphenating shelf{}ful is misleading for first learners since it is the same when TeX hyphenating other words. Could you update your answer with more details about your comment below the original question? That would benifit other people. – Z.H. Oct 28 '14 at 10:58
  • @Z.H. better?.. – David Carlisle Oct 28 '14 at 11:06
  • 1
    @JosephWright Could you please elaborate on the Lua-based ways to suppress ligatures in defined words? Do you have anything else in mind than the selnolig package? – Stephan Hennig Oct 28 '14 at 17:22
  • @StephanHennig - Is there something about the selnolig package you'd like to see changed? – Mico Oct 29 '14 at 06:25
  • @Mico Not at all. I'm interested in the range of existing solutions. I'll give some background to my question if I find some more time. In the meantime, JosephWright, could you please clarify what you were referring to? – Stephan Hennig Oct 29 '14 at 17:57
  • @StephanHennig - Thanks. I'm always eager to find out if people can come up with better methods than those currently used in the selnolig package. :-) – Mico Oct 29 '14 at 17:59