2

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?

ivo Welch
  • 3,766

1 Answers1

2
\documentclass{article}
\usepackage{hyperref}

\makeatletter
\DeclareRobustCommand*{\myurl}{\hyper@normalise\myurl@}
\def\myurl@#1{\hyper@linkurl{See also: \textbf{#1}}{#1}}
\makeatother
\begin{document}

\myurl{https://github.com/latex3/hyperref/issues?q=is%3Aissue+is%3Aopen+tuburl}

\end{document}

Ulrike Fischer
  • 327,261