I want to define something like

\newcommand{\myhref}[2]{\href{#1}{do something with #1}}

and then paste URLs from the web into \myhref{...}{hello}.

The special characters in URLs mean that this works only if I fix up every URL (usually by preceding special characters with a \ ). It would be much more pleasant if I could tell myhref to inherit the rules of treating urls in argument #1 just-as-if-pass-verbatim from/to href.

the question is closely related to Problem with use of '#' in custom \href command . However, I need a more general solution. Unfortunately, URLs cannot just contain # , but _ and & and probably a few more special characters. Is there a more general solution?

1 Answer 1


\def\myurl@#1{\hyper@linkurl{See also: \textbf{#1}}{#1}}



  • 1
    ulrike---can you please give a macro example with two arguments, in which only one argument is the robust URL?
    – ivo Welch
    May 10, 2021 at 3:37
  • Your snippet didn't make use of the second argument, but the inner command can have a second argument. May 10, 2021 at 7:02

You must log in to answer this question.

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