# How to reduce the space between two slashes when using \url?

This is a follow-up question to Space between two slashes. Bianca Lobo's answer (defining a \twobar command with proper kerning) is nice; however, it doesn't work in the argument of the \url command of the package of the same name. How can one reduce the space between two slashes when using \url? (I'm interested in a solution for sans-serif as well as for roman fonts.)

\documentclass{article}

\usepackage{url}

\newcommand{\twobar}{/\kern-0.2em/}

\begin{document}

\sffamily
\urlstyle{sf}

http:\twobar www.tex.stackexchange.com

\url{http://www.tex.stackexchange.com}

\url{http:\twobar www.tex.stackexchange.com}

\bigskip

\rmfamily
\urlstyle{rm}

http:\twobar www.tex.stackexchange.com

\url{http://www.tex.stackexchange.com}

\url{http:\twobar www.tex.stackexchange.com}

\end{document}​


-

The url package has a way how to do search-and-replace in the url strings. See the self-documented code. We tweak into \Url@acthash because it's called by \url exactly at the right place.

\documentclass{article}

\pagestyle{empty}

\usepackage{url}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\makeatletter
% nice "//"
\newcommand{\twobar}{/\kern-0.2em/}
% store original \Url@acthash
\let\orig@Url@acthash\Url@acthash
% make new \Url@acthash that acts "//" as well
\let\new@Url@acthash\Url@acthash
% make \urlstyle use the original \Url@acthash
\let\orig@urlstyle\urlstyle
\def\urlstyle{\let\Url@acthash\orig@Url@acthash\orig@urlstyle}
% make selected url styles use the new \Url@acthash
\makeatother

\begin{document}

\sffamily
\urlstyle{sf}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip

\ttfamily
\urlstyle{tt}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip

\rmfamily
\urlstyle{rm}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip

\end{document}

-
Nice! url is by D. Arsenau, after all. :) –  egreg Feb 16 '13 at 14:57
That's ... egregious. ;-) –  lockstep Feb 16 '13 at 14:59

Define a special behavior for the slash:

\documentclass{article}

\usepackage{url}
\makeatletter
\def\Url@twoslashes{\mathchar\/\@ifnextchar/{\kern-.2em}{}}
\makeatother

\begin{document}

\urlstyle{sf}\url{http://tex.stackexchange.com/4427}

\bigskip

\urlstyle{rm}\url{http://tex.stackexchange.com}

\bigskip

\urlstyle{tt}\url{http://tex.stackexchange.com}

\end{document}


A more complex definition that avoids kerning in tt style is

\def\Url@twoslashes{%
\mathchar\/% print a slash
\expandafter\ifx\UrlFont\ttfamily
\expandafter\@gobble % do nothing if style is tt
\else
\expandafter\@firstofone % check if a / follows and insert a kern
\fi
{\@ifnextchar/{\kern-.2em}{}}
}


Not completely foolproof if silly definitions of \UrlFonts are made for some new style.

-
\def\Url@twoslashes{\@ifnextchar/{\mathrlap{\mathchar\/}\phantom{.}}{\mathchar‌​\/}} –  tohecz Feb 17 '13 at 9:01