I would like to suppress a character from a hyperref link that is built via \url, but the textual representation should keep that character. For example, if the character is *, I want \url{http://tex.stackexchange*.com} act as \href{http://tex.stackexchange.com}{http://tex.stackexchange*.com}.

An embarrassingly failing attempt to hack the \hyper@linkurl macro is given in the MWE, just to show some effort.

       \ifHy@pdfa /F 4\fi
           /IsMap true%

This is trying to make the star active, and let it be replaced by an empty group in the assignment to toks0, but it does not work. It also does not feel right to replicate so much code from hyperref. What is a better way to achieve this?

  • 1
    Would it be that bad to just create your own \Url macro? Mar 22, 2013 at 23:13
  • @Qrrbrbirlbel What do you have in mind? A macro that does all the catcode juggling that hyperref does to get everything printed? Would that be any easier?
    – mafp
    Mar 22, 2013 at 23:18
  • Could you, please, write a bit, why is not possible to use the \href version? (Also, I actually would be interested in the purpose of your aim.)
    – Speravir
    Mar 22, 2013 at 23:30
  • @Speravir The \url are coming from bbl files, formed from user provided URLs. So they are pretty much given. The * shall remain in the link text to be treated with \UrlSpecial for line breaking.
    – mafp
    Mar 22, 2013 at 23:37
  • Sorry, I still don’t get it: Why do you want to show wrong links in your document? Just for line breaking? What is bad on a solution similar to tex.stackexchange.com/a/10419 ?
    – Speravir
    Mar 23, 2013 at 0:15

1 Answer 1


With the etoolbox package, patching of \hyper@linkurl seems easy and is more reliable than the my custom \URL definition (see a previous version of this answer).

This allows to use # and & in URLs.





enter image description here

  • Very good. But this approach removes only the first occurrence of the character, right? And it can not really be extended for all occurrences, right?
    – mafp
    Mar 22, 2013 at 23:44
  • @mafp No, it removes every occurrence, hence the recursive call to \strip@star after checking that #2 is not empty. I’ve added a patch for \hyper@linkurl which seems to work. Of course, the URL needs to be brace-less and should not have any special characters in it, otherwise all bets are off. Mar 22, 2013 at 23:49
  • Whoa, the patching works with URLs containing #,~,=,?. That's it!
    – mafp
    Mar 23, 2013 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .