8

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
8

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

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

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}

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.