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.

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?

share|improve this question
    
Leave a space in the code: \url{# # # #} –  Gonzalo Medina Jul 22 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 at 16:11
    
odd! when I do \detokenize{####} I get eight # in the pdf. –  A.Ellett Jul 22 at 16:12
    
@A.Ellett That's an example of TeX's habit of doubling #'s. –  egreg Jul 22 at 16:12
2  
@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 at 16:19

2 Answers 2

Use href instead:

\href{http://####}{\texttt{\#\#\#\#}}  
share|improve this answer

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}

Result

share|improve this answer

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.