[Tex/LaTex] Add hyphenation pattern for word with special characters

hyphenation

The \hyphenation command can be used to add extra hyphenation patterns globally to a document. This is useful for special words, that are not present in the general hyphenation patterns.

\hyphenation{
  chro-no-ampe-ro-met-ric
  mic-ro-graphs}

The above example results in LaTeX being able to optionally hyphenate the two words "chronoamperometric" and "micrographs" at all places where they contain dashes.

\hyphenation{
  chro-mium-(III)
  chro-no-am-pe-ro-met-ric
  mic-ro-graphs}

I would like to add words such as "chromium(III)" to the hyphenation patterns (as in the example above), but the parentheses cause an error ("Not a letter"). How can words with parentheses be automatically hyphenated?

Ideally, I would also like to be able to specify to LaTeX that for any word that is already in the hyphenation rules, continue to hyphenate it also if it is followed by something within parentheses, and add the possibility to hyphenate between the word and the left parenthesis.

Best Answer

Taking Daи's pointer in the first comment, hyphenation next to a parenthesis, and going to David's Carlisle's answer, reveals that one need not use macros (Mico's suggestion) to accomplish the task. Indeed, hyphenation can even occur within the parentheses, as shown in the last example.

\documentclass{article}
\lccode`\(`\(
\lccode`\)`\)
\lccode`\[`\[
\lccode`\]`\]

\hyphenation{chro-mium-(III)}
\hyphenation{lam-bic-(Bel-gian)} 

\setlength\textwidth{1mm} % just for this example
\begin{document}

. chromium(III) % start with some character b/c pdflatex doesn't hyphenate the first word of a paragraph

. lambic(Belgian)

\end{document}

enter image description here

At that answer, when Lover of Structure asked "Do your first four commands have side effects?", David replied

"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."

I should add (Steven talking again) that David's words "affect hyphenation all over" should not be taken to mean "prevent hyphenation of parenthesized words not specifically set with a hyphenation pattern." In the following MWE, we see that the \lccode definitions do not prevent the hyphenation of words enclosed in parentheses:

\documentclass{article}
\lccode`\(`\(
\lccode`\)`\)
\lccode`\[`\[
\lccode`\]`\]

\setlength\textwidth{1in} % just for this example
\begin{document}
Testing (calisthenics)

Testing calisthenics 
\end{document}

enter image description here