# 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. –  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
show 7 more comments

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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9405063986778259, "perplexity": 6464.000141245721}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-15/segments/1397609537308.32/warc/CC-MAIN-20140416005217-00551-ip-10-147-4-33.ec2.internal.warc.gz"}