[Tex/LaTex] Line break in lines with colons

line-breakingpunctuation

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?

Best Answer

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}