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?

  • 1
    Do you really need verbatim or is \texttt{} enough for you? – Sigur Dec 10 '14 at 16:48
  • 3
    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}:



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

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


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

  • 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.

And now we \href{www.numpy.org}{\numpy}\,.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.