1

When trying to use overlays with code/verbatim commands, I keep running into unexpected runaway argument errors. I've tried various combinations. The following minimal example:

\documentclass[t]{beamer} 

\begin{document}

\begin{frame}[fragile]{X}{}

\onslide<1>{
\begin{verbatim}
    y
\end{verbatim}
}

\end{frame}

\end{document}

causes pdflatex to fail with:

Runaway argument?
 y \end {verbatim} \beamer@spacingcover ^^M^^M
! File ended while scanning use of \@xverbatim.
<inserted text> 
                \par 
l.13 \end{frame}

I've searched through the beamer manual and can find no mention of any restrictions in this respect.

2
  • 1
    You can't put verbatim in an argument: this is entirely general
    – Joseph Wright
    Mar 22, 2023 at 8:50
  • @JosephWright. That's very helpful to know, thanks. Based on your answer, I found the rationale in a TeX FAQ (texfaq.org/FAQ-verbwithin).
    – glyn
    Mar 22, 2023 at 11:14

1 Answer 1

2

@JosephWright already explained in his comment why this is not possible.

To avoid the problem, you can use an environment like onlyenv, uncoverenv or visibleenv:

\documentclass[t]{beamer} 

\begin{document}

\begin{frame}[fragile]{X}{}

\begin{onlyenv}<1>
\begin{verbatim}
    y
\end{verbatim}
\end{onlyenv}

\end{frame}

\end{document}
2
  • Thanks @samcarter_is_at_topanswers.xyz. That solved my larger problem too.
    – glyn
    Mar 22, 2023 at 11:11
  • @You're welcome! Mar 22, 2023 at 11:12

You must log in to answer this question.

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