[Tex/LaTex] How do i put verbatim text as the body of a link

hyperrefverbatim

Is there a way i can have verbatim text inside a link?

\href{www.numpy.org}{\verb|numpy|} does not work. I tried using cprotect;

\cprotect\href{www.numpy.org}{\verb|numpy|}, but then I end up with !TeX capacity exceeded, sorry [input stack size=5000].

Is there a simple way to do this?

Best Answer

You have to brace \href{www.numpy.org}:

\documentclass{article}
\usepackage{cprotect}
\usepackage{hyperref}

\begin{document}

With \texttt{\string\verb}: \cprotect{\href{http://www.numpy.org}}{\verb|numpy|}

With \texttt{\string\texttt}: \href{http://www.numpy.org}{\texttt{numpy}}

\end{document}

However, using \cprotect doesn't seem necessary here, as the example with \texttt shows.

Don't forget http:// or the link won't work.

enter image description here