# how to enforce correct hyphenation of “(near-)uniform” as “(near-)” + “uniform” instead of “(near-” + “)uniform”?

how to enforce correct hyphenation of (near-)uniform as (near-) uniform instead of (near- )uniform?

-
–  lockstep May 30 '12 at 8:54

You can use \discretionary. It takes three arguments:

\discretionary{at line end}{at next line begin}{if not hyphened}


In you case all arguments must be empty. I suggest define a new command for that, like this.

\documentclass{article}

\newcommand{\myhyph}{\discretionary{}{}{}}

\begin{document}
\begin{minipage}{1.5cm}
(near-)\myhyph uniform
\end{minipage}
\end{document}


The {minipage} is only used to get a narrow line in this example.

With

\newcommand{\nbhyph}{\mbox{-}}


You can also define a non breakable hyphen:

(near\nbhyph)\myhyph uniform


I’m sure on can use active characters to make the macros shorter.

Note that babel with (n)german defines several short hands for hyphenations. See the manual on page 81.

You may warp this in new macros to get a short access:

[Update: As egreg said it’s maybe easier to define \newcommand{\sh}[1]{(#1\mbox{-})\discretionary{}{}{}}. I changed it]

\documentclass{article}

\newcommand{\sh}[1]{% s = special, h = hyphen ...
(#1\mbox{-})\discretionary{}{}{}%
}

\begin{document}
\begin{minipage}{1cm}
\sh{near}uniform
\end{minipage}

\end{document}

-
is there also a way to tell LaTeX to get this right automatically, i.e. without changing the text near "(near-)uniform"? –  Walter May 30 '12 at 9:02
You should not call it a 'dash': "You can also define a non breakable dash:" since its a hyphen. –  yo' May 30 '12 at 9:03
@Walter: I added a solution with command, but I guess you can’t tell TeX to do this automatically … –  Tobi May 30 '12 at 9:06
@tohecz: But how should I call it. A “non break hyphen” seems contradictory to me, since a hyphen always appears at line breaks. –  Tobi May 30 '12 at 9:09
@Walter: You can disable the breaks after the hyphen. See my answer here: tex.stackexchange.com/questions/13296/…. But you will still have to insert a breakpoint before "uniform". –  Ulrike Fischer May 30 '12 at 9:13

You could use the german shorthands:

\documentclass{article}
\usepackage[ngerman,english]{babel}

\useshorthands{"}

I'd rather suggest (near"~)""uni"-form. "~ to prevent hyphenation immediately after the dash, and "- to allow hyphenation for the rest of word. –  lockstep May 30 '12 at 8:52
@lockstep The "- in uniform is not necessary. But I add the "~. –  Ulrike Fischer May 30 '12 at 9:02
Adding \declare@shorthand{ngerman}{")}{\mbox{-})\hskip\z@skip} allows for (near")uniform, which might be more appealing. –  egreg May 30 '12 at 9:37