Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}​

enter image description here

share|improve this question

2 Answers 2

up vote 12 down vote accepted

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.

enter image description here

\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
\g@addto@macro{\new@Url@acthash}{\Url@Edit\Url@String{//}{\twobar}}
% 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
\g@addto@macro{\url@rmstyle}{\let\Url@acthash\new@Url@acthash}
\g@addto@macro{\url@sfstyle}{\let\Url@acthash\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}
share|improve this answer
    
Nice! url is by D. Arsenau, after all. :) –  egreg Feb 16 '13 at 14:57
1  
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}{}}
\g@addto@macro\UrlSpecials{\do\/{\Url@twoslashes}}
\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}

enter image description here

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.

share|improve this answer
    
\def\Url@twoslashes{\@ifnextchar/{\mathrlap{\mathchar`\/}\phantom{.}}{\mathchar‌​`\/}} –  yo' Feb 17 '13 at 9:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.