[Tex/LaTex] Hyphenating hyphens: how to change the default \discretionary

discretionaryhyphenationline-breaking

My language, Portuguese, have undergone another orthography reform (those committees simply can't avoid themselves from doing this mess from time to time.) Now we have to adapt, which brings us to my problem.

By the new rule, when a line break occurs at one word's literal hyphen, it should be doubled, appearing at the end of the first line and at the beginning of the second one.

A phrase like “Terão que adaptar-se ou perecer!”, broken at the hyphen, should look like this:

Terão que adaptar-
-se ou perecer!

In TeX terms, each literal hyphen should be replaced by

\discretionary{-}{-}{-}

or followed by

\discretionary{}{-}{}

But TeX's (apparently) hard coded discretionary for literal hyphen is \discretionary{}{}{} (called “empty discretionary”), inserted after every “-” [The TeXBook, p. 95].

The obvious solution

\chardef\hyphen=`\-
\catcode`\-=13
\def-{\penalty\exhyphenpenalty
\discretionary{\hyphen}{\hyphen}{\hyphen}}

is hardly usable because you cannot redefine a character like “-”, heavy used by TeX assignments, without getting too much trouble.

Is there a right way to get this effect? Or only by diving into TeX's source code or waiting for LuaTeX?

Best Answer

One approach without requiring LuaTeX would be to take a similar tack to the way hyphenation is/used to be handled in German. Something like

\documentclass{article}
\catcode`\"=\active
\def"#1{\ifx#1-\discretionary{-}{-}{-}\fi}
\begin{document}
Some filler text. 
Some filler text.
Some filler text.
Some filler text.
Some"-hyphenated word.
\end{document}

Of course, this requires the use of one additional character, which may not be desirable. On the other hand, I don't think that there is a hook in the TeX engine to alter things, so the only 'no input change' way to alter things is I guess to use LuaTeX.

Related Question