# Is it possible to redefine \url in such a way that it works without or with http

This question is related to the question How to avoid the "http:" part in hyperref's \url? and the solutions https://tex.stackexchange.com/a/139934/39306 and https://tex.stackexchange.com/a/139925/39306.

I would like to re-define \url in such a way that the following produce the same result.

\url{ipython.org}


or

\url{http://ipython.org}


(Using \rurl{http://ipython.org} given in the solution above seems to not work, in fact after compiling by pdflatex, clicking on http://ipython.org on pdf file, leads to the nonexistent page http://www.http.com//ipython.org) see the example below based on the solution https://tex.stackexchange.com/a/139934/39306:

\documentclass{article}
\usepackage{hyperref}
\newcommand\rurl[1]{%
}

\begin{document}
\rurl{ipython.org}\\
\rurl{http://ipython.org}
\end{document}

• How shall we help you, if you do not give us any code but the sence "[...] produces error"? tex.stackexchange.com/a/139934 works perfectly for me; have you compiled that? If it does not work, you may want to update your system. – LaRiFaRi Dec 9 '14 at 11:38
• @LaRiFaRi Thank you for your remark, I edited my question. – Name Dec 9 '14 at 12:02
• the \shorturl and \rurl commands in those answers are just for the case without http, leaving \url for the full form. That is probably the most robust/flexible solution why do you need the same command? (it is hard to detect a local link as different from a URL with omitted http if you want to use teh same command) – David Carlisle Dec 9 '14 at 12:19
• @DavidCarlisle Re-defining \url or defining \rurl in order to work without or with http was the main motivation of my question. Just like in the url bar of the web browsers in which writing http : // ipython.org or ipython.org leads to the same page, it would be handy to have the same effect here. – Name Dec 9 '14 at 12:31

\documentclass{article}
\usepackage{hyperref}
\newcommand\rurl[1]{\xurl#1\empty\empty\empty\empty\empty\xurl}
\def\xurl#1#2#3#4#5#6\xurl{%
\def\tmp{#1#2#3#4#5}%
\href{\ifx\tmp\xurlhttp \else http://\fi#1#2#3#4#5#6}%

• @egreg I thought about that but that's a feature I inherited from your code (as it grabbed the URL as #1) so if I get any bug reports I shall pass them on:-) – David Carlisle Dec 9 '14 at 17:19