Text FormattingHyphenation using "\-"

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
hekoushui
Posts: 8
Joined: Sat Jul 31, 2010 6:38 pm

Hyphenation using "\-"

Post by hekoushui »

From the Not so Short Introduction to LaTeX:
The command \- inserts a discretionary hyphen into a word. This also becomes the only point hyphenation is allowed in this word.
I am testing the behavior of "\-". If I make a very long word and insert "\-" in between every single letter, I get some confusing behavior. See the following example:

Code: Select all

\documentclass[draft]{book}

\begin{document}

a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a\-a

\end{document}
In contradiction to the above quotation, LaTeX hyphenates this "word" at multiple places, but I get bad boxes on all the lines it hyphenates.

Why doesn't the hyphenation algorithm appropriately hyphenate the word and thereby avoid bad boxes? If more than one hyphenation point is allowed per word (i.e., the manual is wrong), shouldn't LaTeX be able to prevent bad boxes when it's given every possible hyphenation point?
Last edited by hekoushui on Wed Dec 22, 2010 11:17 pm, edited 1 time in total.

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Hyphenation using "\-"

Post by frabjous »

In contradiction to the above quotation, LaTeX hyphenates this "word" at multiple places, but I get bad boxes on all the lines it hyphenates.
I don't see this as contradicting the quotation. What the quotation is telling you is that it will not hyphenate the word at a place where you do not have "\-". It is not telling you that it will only hyphenate the word once. You have a "\-" everywhere in this string, so everywhere is a legitimate hyphenation spot, and the quotation doesn't say anything about it.
Why doesn't the hyphenation algorithm appropriately hyphenate the word and thereby avoid bad boxes? If more than one hyphenation point is allowed per word (i.e., the manual is wrong), shouldn't LaTeX be able to prevent bad boxes when it's given every possible hyphenation point?
No, you have not given it the option to make the box the right width, and a bad box is unavoidable. There are no spaces in your "word" and so there are no rubber lengths that LaTeX can stretch so that the line ends exactly where it should. Unless the width of the line just happened to be an exact match to a multiple of the width of the letter "a" plus the width of "-", LaTeX has no way of avoiding a bad box here, since there are no rubber spaces. It must either make the line too long or too short. In short, it must make a bad box.

The lshort guide (which is not a manual) is not wrong, and you are simply asking it do the impossible. What are you trying to achieve with this "word" anyway?
hekoushui
Posts: 8
Joined: Sat Jul 31, 2010 6:38 pm

Re: Hyphenation using "\-"

Post by hekoushui »

Thank you for your response.

Please tell me if I am correct: the original sentence from the lshort guide actually means, "only points in the word marked with a '\-' will be be allowed to be hyphenated." If this is correct, does this mean that \hyphenation{} hyphenation points are overruled by "\-"?

I gather from your response that the hyphenation algorithm works only by varying inter-word spacing. If that is the case, I understand why I am getting bad boxes.

In response to your question: I am learning LaTeX, and I like to cook up silly examples to better understand the behavior of its various commands.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Hyphenation using "\-"

Post by frabjous »

hekoushui wrote: Please tell me if I am correct: the original sentence from the lshort guide actually means, "only points in the word marked with a '\-' will be be allowed to be hyphenated." If this is correct, does this mean that \hyphenation{} hyphenation points are overruled by "\-"?
That is my understanding, yes, to both questions, though I've never done the kinds of experiments you are doing to confirm this.
I gather from your response that the hyphenation algorithm works only by varying inter-word spacing. If that is the case, I understand why I am getting bad boxes.
From what I understand, full horizontal justification is effected by stretching all the "rubber lengths" in the right amounts to line up the end of the line of text , with hyphenation being done to minimize the amount of stretching when possible. But when there are no rubber widths, there's nothing to stretch, and hyphenation alone usually isn't sufficient.

By default, if I'm not mistaken, the spacing between words is a rubber length, but the spacing between letters in the same word is not a rubber length. I think it might be possible to make them rubber lengths by modifying the kerning settings and/or using something like the soul package, but I really wouldn't consider experimenting with that unless I had a very good reason.
hekoushui
Posts: 8
Joined: Sat Jul 31, 2010 6:38 pm

Re: Hyphenation using "\-"

Post by hekoushui »

That's a very clear explanation. Thanks again.
Post Reply