3

I know we need to use fragile when using \verb in beamer as explained here. But even with fragile, I get the following error when using \verb in a footnote.

! Missing $ inserted.
<inserted text> 
                $
l.2 \end{frame}
               
? 

How can I fix this?

A minimal example is

\documentclass{beamer}

\begin{document}
\begin{frame}[fragile]{Title}
Text\footnote{\verb|\int|}
\end{frame}
\end{document}
1
  • You can use \footnote{\texttt{\textbackslash int}} instead
    – Cragfelt
    Commented Aug 9 at 23:20

3 Answers 3

3

\verb and {verbatim} do not do well inside other commands. In fact, \verb doesn't work in a footnote even in article, let alone in beamer. (TBH, I'm surprised it works in a frame, even with fragile.)

But in this case, we can get the (desired?) output without \verb: just use \footnote{\ttfamily\textbackslash int}. The first command changes to the \verb style font, and the second gives us the intended backslash. (This does give two warnings about the font that a more knowledgable person may help fix.)

1
  • Thank you! Your solution worked! I also found that if you want the same underscore as in the \verb environment, you can use \string_ in \ttfamily.
    – user108
    Commented Aug 9 at 23:20
2

This doesn't work for every \verb, but in most simple cases it does.

\documentclass{beamer}
\usepackage{fvextra}

\RecustomVerbatimCommand{\verb}{Verb}{}

\begin{document}

\begin{frame}[fragile]{Title}

Text\footnote{\verb|\int|}

\end{frame}

\end{document}

You can also directly use \Verb, of course.

output

2

You could store the problematic content in a savebox:

\documentclass{beamer}

\newsavebox\foo

\begin{document}
\begin{frame}[fragile]
\frametitle{Title}
Text%
\begin{lrbox}\foo%
\verb|\int|
\end{lrbox}%
\footnote{\usebox\foo}
\end{frame}
\end{document}

enter image description here

3
  • The font size is wrong.
    – egreg
    Commented Aug 10 at 13:03
  • @egreg The user can use whatever size they want in the box Commented Aug 10 at 13:06
  • Yes, but why not adding \footnotesize yourself? Anyway, I'd prefer to set the box between paragraphs, so you don't have problems with spurious spaces: <blank line>\begin{lrbox}{\foo}\footnotesize\verb|\int|\end{lrbox}<blank line> Text\footnote{\usebox{\foo}}
    – egreg
    Commented Aug 10 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .