5

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}
CarLaTeX
  • 62,716

1 Answers1

8

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}
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036