Text FormattingPrevent Hyphenation of Acronyms with Hyphens

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

Prevent Hyphenation of Acronyms with Hyphens

Post by ougka »

Hello,

I want LaTeX to not hyphenate some of my acronyms which have hyphens in them! So for example, I usually find my Wi-Fi term being split into two lines, which I would like to avoid.

I tried using the \hyphenation{Wi-Fi} declaration, but it doesn't work. Any suggestions?

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Prevent Hyphenation of Acronyms with Hyphens

Post by cgnieder »

How about defining a custom macro?

Code: Select all

\newcommand*\WiFi{\hbox{Wi-Fi}}
and then use \WiFi in the text body?

Regards
site moderator & package author
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

Re: Prevent Hyphenation of Acronyms with Hyphens

Post by ougka »

Thanks for your reply Clemens.

A macro could work but has the following problems :
a) Latex treats it as an hbox (obviously), so in almost all the circumstances that I've checked the hbox exceeds the normal line's width on the right, which is pretty annoying. It doesn't try to put the hbox in the line's width so that it pushes it all to the next line and space out the text (which would be my preferred way).
b) I have to go over ALL the problematic acronyms in my text and do sth like \WiFi, which in all honesty is a trouble I would like to avoid.

It would be highly preferable to be able to declare this in a command at the beginning, as you do with the \hyphenation{} and then let Latex deal with it.

Any other suggestions?
Thanks
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Prevent Hyphenation of Acronyms with Hyphens

Post by cgnieder »

ougka wrote:A macro could work but has the following problems :
a) Latex treats it as an hbox (obviously), so in almost all the circumstances that I've checked the hbox exceeds the normal line's width on the right, which is pretty annoying. It doesn't try to put the hbox in the line's width so that it pushes it all to the next line and space out the text (which would be my preferred way).
This depends on the lines badness after/before breaking. You want to prevent TeX from breaking Wi-Fi which it did because it calculated it to be the best solution. Since this is not allowed anymore you will naturally get bad boxes and have to tweak or re-arrange the text in some cases. TeX is only allowed to stretch and shrink the interword space a certain amount (depending on several factors like the font). I'm sure TeX tried to put the box on a new line but hasn't found any solution without infinite badness.
ougka wrote:b) I have to go over ALL the problematic acronyms in my text and do sth like \WiFi, which in all honesty is a trouble I would like to avoid.
I'm afraid there won't be a way to avoid that. You'd have to do some “search & replace”. Good thing is: once you've done that you can change layout and boxing at one place in the preamble.
ougka wrote:It would be highly preferable to be able to declare this in a command at the beginning, as you do with the \hyphenation{} and then let LaTeX deal with it.
There is no opposite for \hyphenation that I know of except for boxing.
ougka wrote:Any other suggestions?
I'm afraid not.

Regards
site moderator & package author
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

Prevent Hyphenation of Acronyms with Hyphens

Post by ougka »

Thank you for your reply Clemens!
cgnieder wrote:
ougka wrote:A macro could work but has the following problems :
a) Latex treats it as an hbox (obviously), so in almost all the circumstances that I've checked the hbox exceeds the normal line's width on the right, which is pretty annoying. It doesn't try to put the hbox in the line's width so that it pushes it all to the next line and space out the text (which would be my preferred way).
This depends on the lines badness after/before breaking. You want to prevent TeX from breaking Wi-Fi which it did because it calculated it to be the best solution. Since this is not allowed anymore you will naturally get bad boxes and have to tweak or re-arrange the text in some cases. TeX is only allowed to stretch and shrink the interword space a certain amount (depending on several factors like the font). I'm sure TeX tried to put the box on a new line but hasn't found any solution without infinite badness.
Well, I understand the above, but I would want from Latex to push Wi-Fi to the next line and space out the previous line a bit... after all it is just a few letters so I would think that this wouldn't be a problem... :(
cgnieder wrote:
ougka wrote:b) I have to go over ALL the problematic acronyms in my text and do sth like \WiFi, which in all honesty is a trouble I would like to avoid.
I'm afraid there won't be a way to avoid that. You'd have to do some “search & replace”. Good thing is: once you've done that you can change layout and boxing at one place in the preamble.
Well yes it is a search & replace think but think of all the captions, tables etc where I wouldn't want to have boxes cause they will be messing up with things... Also, it is not just Wi-Fi that I have a problem with, I have tens of other examples, I am afraid, EAP-TLS, EAP-TTLS, real-world, on-the-go etc...

I've just found this which might help http://java.ugent.be/~tdemedts/latex.php

So essentially do something like :

Code: Select all

 \newcommand\n{$n$\nobreakdash-\hspace{0pt}}
 Consider the \n dimensional manifold ... 
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Prevent Hyphenation of Acronyms with Hyphens

Post by cgnieder »

Maybe you can try to put together a Infominimal working example. It's easier to look for solutions with some code to play with. I have a feeling though, that every solution will involve manual interaction in various places and possibly/probably changing all acronyms to macros or calls to \ac (of the acronym package).

Regards
site moderator & package author
Post Reply