[Tex/LaTex] How to emulate \url hyphenating without using the url package

hyphenationurls

I'm forced to avoid the url package in a proceedings paper (!) but my bibliography includes a long URL. I already

\newcommand{\url}[1]{{\tttext{#1}}}

but the URL spills over to the margin as it isn't hyphenated. I would rather not change the bibliography manually to add the hyphens (my current solution) but rather define the new \url command to put in the \- commands before dots and forward slashes. I've seen a few related questions but close enough for my TeX skills…

Also, is there a way to make the hyphenation happen without an actual hyphen?

EDIT: sorry, I should have said, that not only the url package is disallowed…but I cannot include any extra package. the packages that are included are

graphicx multicol footmisc amsmath amsfonts

So I guess this is a plainTeX question.

Best Answer

Without any package, your only hope is that they use a fairly recent TeX distribution:

\newcommand{\url}[1]{%
  \begingroup
  \ttfamily
  \begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
  \begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
  \catcode`/=\active\catcode`.=\active
  \scantokens{#1\noexpand}%
  \endgroup
}

This will allow breaks after periods and slashes.

If you have some special character in your URLs, they can be taken care of, just present some examples.