Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
Related: tex.stackexchange.com/questions/27198/… –  lockstep May 30 '12 at 8:54

2 Answers 2

up vote 10 down vote accepted

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}

discretionary

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}
share|improve this answer
    
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. –  tohecz 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{"}
\addto\extrasenglish{\languageshorthands{ngerman}}
\begin{document}
\begin{minipage}{1.5cm}
(near"~)""uniform
\end{minipage}
\end{document}
share|improve this answer
    
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
    
Is there a way without using additional packages? –  Walter May 30 '12 at 8:57
1  
@lockstep The "- in uniform is not necessary. But I add the "~. –  Ulrike Fischer May 30 '12 at 9:02
3  
@Walter: Using babel (for hyphenation) is a good idea anyway. Also: if you don't like to load packages, don't use LaTeX. It is part of the LaTeX philosophy to have a rather small core and to activate additional features through packages. And at last: naturally you could define such shorthands yourself by copying the babel definitions. –  Ulrike Fischer May 30 '12 at 9:06
3  
Adding \declare@shorthand{ngerman}{")}{\mbox{-})\hskip\z@skip} allows for (near")uniform, which might be more appealing. –  egreg May 30 '12 at 9:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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