# Re: [NTG-context] modifying URL wrapping rules

On Fri, Nov 21, 2008 at 8:31 PM, Lars Huttar wrote:
> On 11/21/2008 12:01 PM, Lars Huttar wrote:
>>
>> So as far as we know, nobody has successfully used
>> \sethyphenatedurlbefore/after/etc. to tune the url-breaking mechanism.
>> Has anybody else on the list done this?
>
> OK... I have a working workaround... close your eyes, because it's ugly.
>
> I just put \hbox{} around the sections that we don't want broken, and
> \discretionary{}{}{} in the places we will allow a break:
>
> \hbox{http://}\discretionary{}{}{}\hbox{www}\discretionary{}{}{}\hbox{.sil}\discretionary{}{}{}\hbox{.org/}\discretionary{}{}{}\hbox{silesr/}...
>
> One of our URLs goes from 89 to 391 characters!  :-p
>
> Maybe posting this awful kluge to the list will motivate someone who
> knows TeX better to post a more elegant solution. :-)

I don't know many details about TeX, but simple tests like the one
below seem to work:

\bgroup
\catcode\:=11
\catcode\/=11
\catcode\~=11
\catcode\,=11
\catcode\-=11
\catcode\_=11
\catcode\?=11

\lccode\:=\:
\lccode\/=\/
\lccode\~=\~
\lccode\,=\,
\lccode\-=\-
\lccode\_=\_
\lccode\?=\?

% not sure how to handle the dot, but this seems to work
\catcode\.=11
\catcode\^=11
\lccode\^=\.

\patterns{
8:3 % break after  : (never before)
3^8 % break before . (never after)
8/3 % break after  / (never before)
3~8 % break before ~ (never after)
3,8
3-8
3_8
3?8
}
\egroup

And then an ugly document (after selecting the proper language):

\bgroup
\catcode\:=11
\catcode\.=11
\catcode\/=11
\catcode\~=11
\catcode\,=11
\catcode\-=11
\catcode\_=11
\catcode\?=11

\lccode\:=\:
\lccode\.=\.
\lccode\/=\/
\lccode\~=\~
\lccode\,=\,
\lccode\-=\-
\lccode\_=\_
\lccode\?=\?

\showhyphens{http://www.sil.org/silesr/}

hello
\egroup

This returns
http://-www-.sil-.org/-silesr/
But one would need to complete the rules above (should be almost
trivial), and of course one would need to write all the needed macros
to use the "url language" automatically when typesetting URLs.

Mojca
___________________________________________________________________________________
`