How to prevent LaTeX from hyphenating words containing a dash?
Asked Answered
P

3

7

I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.

One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).

Presuppose answered 4/1, 2011 at 14:44 Comment(1)
Recommend asking on tex.stackexchange.comJarredjarrell
C
9

Why is defining a new command ugly? It's how \LaTeX\ defines itself.

\def\ObjectiveC{\mbox{Objective-C}}
Colchester answered 4/1, 2011 at 14:54 Comment(1)
Thanks! I guess there really is no other way, unfortunately.Presuppose
T
3

Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.

Tong answered 4/1, 2011 at 15:27 Comment(0)
O
2

As suggested here, you could define a command like this:

 \newcommand\dash{\nobreakdash-\hspace{0pt}}

and use it like this

Consider the $n$\dash dimensional manifold ... 

Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.

Oxytocic answered 4/1, 2011 at 15:1 Comment(1)
Thanks for your suggestions! All of that works, but can not be defined globally, like the \mbox solution :(Presuppose

© 2022 - 2024 — McMap. All rights reserved.