# How do i put verbatim text as the body of a link?

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?

• Do you really need verbatim or is \texttt{} enough for you? – Sigur Dec 10 '14 at 16:48
• I'd try \cprotect{\href{www.numpy.org}}{\verb|numpy|}, but \href{www.numpy.org}{\texttt{numpy}} is much easier. – egreg Dec 10 '14 at 16:48
• Possible duplicate: How to put \verb command inside of \textbf block? (different error message, but same cause/solution). – Werner Dec 10 '14 at 17:15
• @Werner No, the OP already know about \cprotect. – egreg Dec 10 '14 at 17:25

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.

• Thanks. It works for me without the http:// though, should it not? – will Dec 10 '14 at 18:47
• @will This depends on features of the PDF viewer. It doesn't with Skim, for instance. – egreg Dec 10 '14 at 19:01

Here's a way using a verbatimbox.

\documentclass{article}
\usepackage{verbatimbox,hyperref}
\begin{document}
\begin{myverbbox}{\numpy}n\$_umpy\end{myverbbox}
And now we \href{www.numpy.org}{\numpy}\,.
\end{document}