I have some very special hyphenation puzzles involving optional hyphens next to parentheses.

  • (semi)group should be hyphenated as (semi-)/group
  • di[rected ]graph should be hyphenated as di-/[rected ]graph or di[rec-/ted ]graph or <di[rected]/graph or di[rected]-/graph - I can't make up my mind> (whichever hyphenation leads to the most even inter-word spacing, with LaTeX choosing among all three possibilities)

How can I achieve such hyphenation?

Note: Anyone tackling this problem in the most general form (esp for the details mentioned in the @egreg answer) might want to set \righthyphenmin=2.

2 Answers 2


A more generic strategy that doesn't require changing internal tables.

Define two commands:


For the second one the usual \- suffices. For the first one the more powerful \discretionary is needed:


If a line break (for hyphenation) takes place at the discretionary item, the <prebreak> text will be at the end of the line and the <postbreak> text at the start of the next line; otherwise <nobreak> will be used.

Don't forget to type \semigroup{} if a space follows.

In case you change your mind about \digraph it will be easy to change its definition than hunting through the document for it.

Another definition for \digraph allowing hyphenation after the closing bracket might be


(there can't be flexible spaces in the <nobreak> text).

I don't think that infrequent "words" such as "(pseudo)scientific" (the full "pseudoscientific" is normally written without a hyphen) warrant a special treatment: it's easier to decide about hyphenation when the text is finished. However, you could make up your personal command:


and input it as


The "pseudo" part would never be hyphenated. If that's desired, just change the definition into


In order to do the same (i.e. retain all hyphenation possibilities) for "(computer-)aided" (hyphenation: com·put·er and aid·ed) with a hard hyphen, one can define


Note: The definition of \myallowhy is modelled on Babel's \allowhyphens that can't be used here, because it's a no-op when the T1 encoding is in force.

Since \nobreak is used after \makeatletter its use is justified.

  • I am impressed! Feb 3, 2013 at 10:15
  • As an explanation for others, about my addendum re "(computer-)aided", which has a hard hyphen: I've experimented with -\nolinebreak)\hskip0pt and \hyp\nolinebreak)\hskip0pt (with \hyp from the hyphenat package) but ended up with linebreaks before the ")" in some cases. I don't know why. But your \discretionary{-)}{}{-)} with your \myallowhy seems to work. Feb 6, 2013 at 0:30
  • Could you explain your remark that "[s]ince \nobreak is used after \makeatletter its use is justified."? Jun 16, 2013 at 11:29
  • @LoverofStructure People using \makeatletter on their own initiative should know what they're doing. In particular that \nobreak should be issued when it's possible to know what mode it will appear in.
    – egreg
    Jun 16, 2013 at 12:21
  • I would say this is not about \makeatletter per se but more about you having a concrete justification (namely, knowledge of the mode not being v-mode) here. Jun 17, 2013 at 12:35

\hyphenation{(semi-)group di-[rec-ted}

\showhyphens{(semi)group di[rected ]graph}


shows the possible hyphenation points as

[] \tenrm (semi-)group di-[rec-ted ]graph
  • did you miss one: di[rected]-/graph ? Feb 1, 2013 at 15:41
  • 1
    @barbarabeeton I didn't miss it, I just didn't do it, the OP had the space inside the bracket which means doing anything else would need a macro and explicit discretionary at that point rather than a simple hyphenation table entry. Feb 1, 2013 at 17:46
  • 1
    Do your first four commands have side effects? Feb 2, 2013 at 8:20
  • 4
    @LoverofStructure yes they make ()[] letters for the hyphenation algorithm so (foobar) will be looked up as the 8 letter word (foobar) not the 6 letter word foobar, this can affect hyphenation all over. But if you restrict it to areas just containing technical constructs it's probably ok as natural language hyphenation patterns are not always appropriate there anyway. Feb 2, 2013 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.