Hyphenating hyphens: how to change the default \discretionary

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.


A more elegant approach would be to use babel command shorthand \babelhyphen{repeat} (section 1.5) to define a new character (or in this case two) for a repeatable hyphen. It's designed specifically for that (see this question):

hard hyphen inside compound words are repeated at the beginning of the next line.

Something like this:

    \documentclass{article}
    \textwidth=5cm % just making easier to spot with less text
    \usepackage[brazil]{babel}
    \defineshorthand{"-}{\babelhyphen{repeat}} % generates a hyphen that will repeat on a new line
    \begin{document}
Text Text Text Text sabendo-se % without repeated hyphen

Text sabendo-se                % won't repeat anyway    

Text Text Text Text sabendo"-se % with repeated hyphen

Text sabendo"-se                % won't repeat anyway
    \end{document}

screenshot showing the repeated hyphen

Yes, it sill makes the the code look weird and demands author to type an extra character every time, but it works and it's simple.


The alternative I commonly use is the redefinition of the underscore to provide this doubled-when-broken hyphen:

\let\oldunderscode=_
\catcode`\_\active
\def_{\ifmmode\oldunderscore\else\discretionary{-}{-}{-}\fi}

This keeps the meaning of _ in mathematical mode, which is essential!! Also, take care not to use _ in your labels, as they will not work. I usually write \label{my-section} anyway, so this is not a problem for me.

Now, you just need to write Terão que adaptar_se ou perecer!, which I think is still very readable and has the advantage of using a single character as well.

I usually place code similar to that in a separate .sty file which I import whenever I need it. This package helps me write small portions of Portuguese text inside documents with English as main language, which changes hyphenation rules (provided babel is loaded with Portuguese language) and also emits a \frenchspacing that disables the "double space" at the end of sentences that is traditional in English typography but not in Portuguese.