# Line break in lines with colons

I noticed that if I've got something like this:

one::two::three::four one::two::three::four one::two::three::four


something weird happen:

%                      the right page margin would be here |
%                                                          |
%                                                          v
one::two::three::four one::two::three::four one::two::three::four


the page margin is where I marked, but the line doesn't get broken, ::four goes out of the page, although it is aligned so that the first colon is exactly after the margin, like if it had to be splitted.

Why doesn't the line gets broken between one::two::three and ::four?
And then why does it get aligned that way, so that ::four goes out of the page?

-

It doesn't get broken there because TeX breaks lines only at white space, hyphenation points, or at explicitly inserted invocations of \discretionary. You could put \discretionary{}{}{} before each double colon if you wish to allow a line break there. If you need this a lot, make a shorter macro for it.

-
Yeah, need it quite a lot, will create a command for it, thanks! Anyway why does LaTeX put ::four after the right page margin, rather than putting the whole word (one::two::three::four) on a new line? That looked quite weird to me. –  peoro Jan 15 '11 at 13:23
@peoro: I'm pretty sure it's coincidence. –  Hendrik Vogt Jan 15 '11 at 13:27
@peoro: I guess that you typeset your text justified and that TeX couldn't find an acceptable solution for line-breaking (putting the whole third "word" on a new line would have created too much whitespace in the first line). –  lockstep Jan 15 '11 at 13:35
Uh, yeah, it looks like you guys are right. I am such a newbie with LaTeX, although I'm using it quite a lot... –  peoro Jan 15 '11 at 15:17

You could define

\def\::{\discretionary{:}{:}{::}}


Now just write \:: and :: would be splitted into : and : at the end of a line. You could easily change it to behave differently, such as

\def\::{\discretionary{::}{}{::}}


That's a benefit of a LaTeX macro: once you defined and used it, you might easily change it consistently.

A minimal example, as requested in a comment:

\documentclass{article}
\def\::{\discretionary{::}{}{::}}
\begin{document}
one\::two\::three\::one\::one\::two\::three\::one\::two\::three\::
four::one\::two\::three\::four\::one\::two\::three\::four
\end{document}

-
Thanks, I'm using your second directive, the result is exactly what I wanted. –  peoro Jan 15 '11 at 15:18
@Stefan Thanks a lot! –  Yiannis Lazarides Jan 15 '11 at 19:04
@peoro Could you mark this as the "selected" answer then? :) –  mpr Oct 30 '11 at 4:28
It should be remarked that this overrides the definition of \:, which might be used for spacing in math formulas. –  egreg Jan 14 '12 at 21:18
\documentclass{article}