4

I know that to use \verb|...| in a beamer presentation you have to add the fragile option to the frame environment.

But if I use \verb|...| in the main \title of \titlepage it gives me the error:

Runaway argument?
guide to \relax \hbox {}#I\catcode `\ \active \<let>-command \csname\endcsname 
! Paragraph ended before \HyPsd@@ProtectSpacesFi was complete.
<to be read again> 
 \par 
l.5 \begin{document}

How can I solve it?

MWE:

\documentclass{beamer}
\usetheme{Madrid}
\title{Quack guide to \verb|\usepackage{tikzducks}|}

\begin{document}

\begin{frame}[fragile=singleslide]
    \titlepage
    Why this doesn't work\dots
\end{frame}

\begin{frame}[fragile=singleslide]
    \dots whereas this \verb|\usepackage{tikzducks}| works?
\end{frame}

\end{document}
  • 1
    Quack guide to \texttt{\string\usepackage\string{tikzducks\string}}, perhaps – egreg Jan 4 '17 at 17:40
  • @egreg Joseph Wright was quicker than you, both his first solution and yours work :) – CarLaTeX Jan 4 '17 at 17:47
  • @egreg ...also his second one, only an \end{document} was missing :) – CarLaTeX Jan 4 '17 at 20:47
  • Possible duplicate: Verbatim inside a command – Werner Jan 4 '17 at 21:09
5

As with any other case: you can't use \verb in the argument to \title. There's always a way of writing the text of a \verb out 'in full', here using \{, \} and \textbackslash:

\documentclass{beamer}
\usetheme{Madrid}
\title{Quack guide to \texttt{\textbackslash usepackage\{tikzducks\}}}

\begin{document}

\begin{frame}[fragile=singleslide]
    \titlepage
    Why this doesn't work\dots
\end{frame}

\begin{frame}[fragile=singleslide]
    \dots whereas this \verb|\usepackage{tikzducks}| works?
\end{frame}
\end{document}

One could also use the cprotect package as described in How to put \verb command inside of \textbf{} block?, which would give

\documentclass{beamer}
\usepackage{cprotect}

\usetheme{Madrid}
\cprotect\title{Quack guide to \verb|\usepackage{tikzducks}|}

\begin{document}

\begin{frame}[fragile=singleslide]
    \titlepage
    Why this doesn't work\dots
\end{frame}

\begin{frame}[fragile=singleslide]
    \dots whereas this \verb|\usepackage{tikzducks}| works?
\end{frame}
\end{document}
  • Your second solution gives an error... – CarLaTeX Jan 4 '17 at 17:45
  • @CarLaTeX I've just run that code exactly as given with the current release of beamer: it should work fine – Joseph Wright Jan 4 '17 at 17:48
  • ... but if I use @egreg's solution (given in a comment) can I accept this answer? – CarLaTeX Jan 4 '17 at 21:03
  • @CarLaTeX You can ask him to post a separate answer, though it's much the same as my first suggestion (there are various ways to input non-verbatim versions of what you want). – Joseph Wright Jan 4 '17 at 21:04
  • Eventually, thinking of it better, I've accepted your answer because the solution with \cprotect is more generalized. – CarLaTeX Jan 4 '17 at 21:33

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.