Text FormattingBreaking a long word without hyphenation - how?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
liebichw
Posts: 3
Joined: Fri Feb 13, 2009 9:20 am

Breaking a long word without hyphenation - how?

Post by liebichw »

Hi,
I'm writing on a rather long program documentation, for a JAVA program.
This document contains some pretty long words - for example fully qualified class names (including package names).
These words have non alphanumeric characters in them (like '.' or '_') and are not hyphenated.
They often lead to "overfull hbox" warnings, and I want a method of "silent hyphenation" for them - allow them to be broken (maybe even at defineable "break points") BUT no hyphenation character must be shown (because this could confuse the reader into believing the hyphen char to be part of the word itself).
IOW I want something similar to the way the URL package is (reputedly) handling long strings.
There IS some way of "silent hyphenation" IIRC --- but I can't find where I read about it :-(
Can anyone here help me out?
TIA,
Wolfgang Liebich

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Breaking a long word without hyphenation - how?

Post by localghost »

Have a look at the listings package for writing code in a certain programming language. It has predefined languages and JAVA is one of them.


Best regards and welcome to the board
Thorsten¹
liebichw
Posts: 3
Joined: Fri Feb 13, 2009 9:20 am

Re: Breaking a long word without hyphenation - how?

Post by liebichw »

Thanks, I will look into the package.
But I don't really want to type set listings --- my book is ordinary text, with some really long words interspersed which should not get hyphenated -- but just word breaking them would be OK (like fully qualified java class names, or config entry names --- which can be very long due to obscure reasons).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Breaking a long word without hyphenation - how?

Post by localghost »

The package is not only for long listings, but also provides the \lstinline|…| command which may support line breaks.
liebichw
Posts: 3
Joined: Fri Feb 13, 2009 9:20 am

Re: Breaking a long word without hyphenation - how?

Post by liebichw »

Thanks for the tip --- but according to some forum posts I've googled now, \lstline does not support breaking a word :-/
I seem to remember a variant of \- where there's no hyphen shown, but just a word break - unfortunately I cannot remember WHERE I read that :-(
Does anyone besides me remember reading something like that?
- Ciao, Wolfgang
mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Re: Breaking a long word without hyphenation - how?

Post by mas »

I tried \def\-{\discretionary{}{}{}} and it worked.

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
logger
Posts: 2
Joined: Fri Nov 20, 2009 2:05 am

Re: Breaking a long word without hyphenation - how?

Post by logger »

What does this \descretionary command do? I'm having a hard time finding any explanation. I think I'm in the same boat as the OP. I'm documenting an ASIC verification environment. I need to break a long line that looks like:

env.soc_top.soc_core.blk_a.foo_blk.bar_blk

I'd like latex to break on a period, without a hyphen. So that could become:

env.soc_top.soc_core.blk_a.
foo_blk.bar_blk

Other than this change, I'd like normal hyphenation rules to remain the same.

I added \def\-{\discretionary{}{}{}} to my file and it didn't change a thing.

Regards.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Breaking a long word without hyphenation - how?

Post by gmedina »

Hi,
logger wrote:What does this \descretionary command do? I'm having a hard time finding any explanation. I think I'm in the same boat as the OP...
Please refer to section 19.3 Discretionaries (pp. 163ff.) of the book TeX by Topic by Victor Eijkhout.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
logger
Posts: 2
Joined: Fri Nov 20, 2009 2:05 am

Re: Breaking a long word without hyphenation - how?

Post by logger »

gmedina, thanks for that pointer. That is a very good resource!

I first tried:

\def\.{\discretionary{.}{}{.}}

env\.soc_top\.soc_core\.blk_a\.foo_blk\.bar_blk

But I found that some other macros seem to reset \.

So I switched to:

\def\/{\discretionary{.}{}{.}}

env\/soc_top\/soc_core\/blk_a\/foo_blk\/bar_blk

That works, and doesn't get reset.

The results are acceptable, but not optimal. I am getting "Overfull \hbox (38.73192pt too wide) in paragraph ..." messages. It will break a line like:

env.soc_top.soc_core.blk_a.foo_blk.
bar_blk

But "foo_blk." is still overflowing into the margin. It should have produced:

env.soc_top.soc_core.blk_a.
foo_blk.bar_blk

Any suggestions on how to improve this?

Regards.
ulmoo
Posts: 1
Joined: Sat Dec 04, 2010 5:54 pm

Breaking a long word without hyphenation - how?

Post by ulmoo »

It's kind of a hack, but you can use:

Code: Select all

Gutenacht\nolinebreak[0]geschichte
It's basically a request not to break the line at that point, but with a low priority (scale is from 0 to 4, with 4 as the highest priority). The result is that LaTeX usually won't break the line at that point, but it will break it if it's really necessary - without a hyphen.
Post Reply