# Using verbatim within a onslide environment [closed]

I want to use \onslide<2-> with verbatim environment inside in beamer, e.g.:

\onslide<2->{
\verb+foo+
}


This does not work due to overlays and verbatim conflicts... I found out that there is a onlyenv environment that fixes the issue for \only but I cannot find anything for \onslide.

Is there some equivalent to onlyenv for onslide?

• Do you try to add to frame option fragile: \begin{frame}[fragile]? – Zarko Jul 28 '19 at 14:46

According to, e.g., this answer: Uncover lstlisting on a particular slide using \onslide or \uncover, there is no such equivalent, and I also could not find any. You can user \onlyenv with an overlayarea environment to avoid jumps due to overlay animations. This however forces you to initially fix the dimensions of the animated area, which you don't have to when you're using \onslide...