# Discretionary hyphen destroys kerning and ligature

Consider the following example (plain TeX format):

VA fi\par
V\-A f\-i
\bye


I tried TeX, pdfTeX, XeTeX, and LuaTeX, but the second line looks the same as the first line only when using LuaTeX. My questions are:

1. Is this an intended behaviour?

2. Is it difficult or impossible to make other TeX engines act like LuaTeX (discretionary hyphen does not destroy kerning and ligature)?

3. How can I work around this problem?

• \discretionary{f-}{i}{fi} Nov 10, 2017 at 11:47

\discretionary{f-}{i}{fi} seems to work. You can define a macro to ease the use:

\def\dfi{\discretionary{f-}{i}{fi}}
\def\VA{\discretionary{V-}{A}{VA}}
VA fi\par
AD\VA NCE Nar\dfi na
\bye


Not ideal but if you don't have many problems, you could work with that.

In any case, hyphenation is not something user should worry much in theory, do you have the correct language set in your document? That comes with many rules to tell TeX how to break up words. And you also have \hyphenation{wordwithf-ibreak wordwithV-Abreak} to add rules for particular words; it does work well (ligature when not broken, and broken correctly, plus you set it up once for the whole document).

Rant/Question: I don't understand why \- is a primitive. What was the need? Couldn't it be just defined in terms of \discretionary? It's one of those doubts I have about TeX :)

• Regarding the claim that \- is a primitive: it's not true. Instead, \- gets expanded to \discretionary{-}{}{}.
– Mico
Nov 10, 2017 at 12:34
• Regarding the last part, I haven't looked into this one, but TeX does contain, for efficiency, primitives that can be defined in terms of others: for example \hss (and arguably even \hfill). Nov 10, 2017 at 12:35
• @Mico I think it is. Not that it cannot be redefined (in fact it is redefined) but it is a primitive originally. ShreevatsaR, What would be the definition of \hss? I always thought \hfill was a macro! And another thing that comes to memory is that I don't understand why the particular definition of \hidewidth :) Nov 10, 2017 at 12:42
• @Mico I just checked with \edef\q{\-} and it does indeed expand (this I thought wouldn't happen), so \- is an expandable primitive that expands to \discretionary{-}{}{}, but it has been defined “by some means other than” \def\-{\discretionary{-}{}{}} (although the result is exaclty the same). @ShreevatsaR Thanks for the info ;) Nov 10, 2017 at 14:24
• @Manuel I tried \edef\q{\-} and it doesn't expand to anything other than \-. Are you sure you tried it in TeX (where \- is a primitive) and not in LaTeX (where \- has been overwritten, defined as a macro)? Nov 10, 2017 at 16:32

By default, the control sequence \- is an abbreviation for

\discretionary{-}{}{}


(see p. 95 of the TeXbook). The first argument of \discretionary, the prebreak, specifies what gets inserted immediately before the linebreak if a linebreak is inserted (here: a hyphen character). The second argument, the postbreak, specifies what's inserted immediately after the line break if a linebreak occurs (here: nothing). The third argument, the nobreak, specifies what gets typeset if no linebreak occurs -- here: nothing or, more precisely and crucially, an empty token, {}.

For the sake of specificity, consider the following example: half\-line. This first gets expanded to half\discretionary{-}{}{}line. Suppose the word does not get broken up at the end of a line. What happens next depends on which TeX engine is in use.

• Assuming pdfLaTeX is in use, what gets typeset is half{}line, and the fl ligature is (correctly!) broken up, since that is what's supposed to happen if f{}l is encountered.

• In contrast, under LuaLaTeX all text-mode instances of {} are discarded prior to final processing. Therefore, halfline is processed without the {} between f and l, and the fl ligature is (incorrectly in this case) not broken up.

• What happens under XeLaTeX depends partly on the version of XeLaTeX that's in use on your system. E.g., if you use TeXLive2018, halfline and half\-line are both typeset with an fl-ligature if no line break occurs between half and line. At some in the not-too-distant past, though, the fl-ligature was suppressed if half\-line was encountered.

To verify these claims, simply compile the following document under pdfLaTeX, XeLaTeX, and LuaLaTeX:

\documentclass{article}
\begin{document}
halfline half\-line
\end{document}


For "plain" pdfTeX, XeTeX, and LuaTeX, simply run

halfline half\-line
\bye


To get all three engines to produce the same output, don't write half\-line. Instead, write hal\discretionary{f-}{l}{fl}ine. That way, the fl-ligature will be used whenever no line break occurs.

• Good morning to you. Why do not see in chat? +1. Nov 10, 2017 at 12:47
• @Mico Knuth admits at the outset to be telling some white lies; actually, \- stands for \discretionary{\char\hyphenchar\font}{}{}; if a font sets \hyphenchar to −1, you get a (possible) break with no character inserted. Which explains why LaTeX redefines it to insert, if \hyphenchar\font is negative, the \defaulthyphenchar. Nov 10, 2017 at 14:08
• About \- being a primitive, see tex.web section 1114 (see also section 208); \- and \discretionary are two “flavors” (same eq_type, but different equiv) of the same primitive command. The different actions of these two flavors correspond to the two branches of the outer if in section 1117. (This comment might interest @egreg too.)
– GuM
Nov 10, 2017 at 18:44
• @GuM You spared me a search! ;-) By the way, the third doubly dangerous paragraph on page 455 of the TeXbook says that \- is equivalent to \discretionary{\charh​ }{}{}, where h is the \hyphenchar of the current font. Nov 10, 2017 at 18:52
• @egreg: …and you didn’t need to search for that because p. 455 is the main (underlined) reference for \- in the index. ;-)
– GuM
Nov 10, 2017 at 18:56