\#\#\#\# becomes “##” in printout

I want to refer to a url using "####" as a stand-in for the many four digit codes which could take it's place. But this ...

\documentclass{scrartcl}
\usepackage{url}
\usepackage{hyperref}

\begin{document}
\url{\#\#\#\#}
\end{document}

... is printing this "##". \detokenise{####} does the same. Without hyperref it prints "####" as I want. Why? and How to fix?

-
Leave a space in the code: \url{# # # #} –  Gonzalo Medina Jul 22 '14 at 16:08
It seems that \url is overly zealous and assumes two consecutive # come from TeX's habit of doubling those tokens in output, so it reduces ## to #. If you use ######## you get ####; or do what Gonzalo says. –  egreg Jul 22 '14 at 16:11
odd! when I do \detokenize{####} I get eight # in the pdf. –  A.Ellett Jul 22 '14 at 16:12
@A.Ellett That's an example of TeX's habit of doubling #'s. –  egreg Jul 22 '14 at 16:12
@A.Ellett it gets halved when making a definition def\foo{##} is a single # so \meaning and \show and similar commands double any # they find \meaning\foo shows two # so if you use meaning as a "poor man's verb" then it's common to post-process the result to replace ## by # but if you managed to get a literal ## into the replacement that would be the wrong thing to do:-) –  David Carlisle Jul 22 '14 at 16:19

\href{http://####}{\texttt{\#\#\#\#}}
-

hyperref is sanitizing the arguments of \href and \url. Then the category code of # in the string is 12 (other). Two tokens are then replaced by package url by one hash.

I am reluctant to change the normalization in hyperref, because the normalized string is also used in other contexts, e.g. the URL of \href or \url is also used in the link annotation.

However, there is no valid URL here, thus a link annotation has no target in reality. Then \Hurl can be used that is the saved original \url of package url:

\documentclass{scrartcl}
\usepackage{hyperref}

\begin{document}
\Hurl{####}
\end{document}

-