3

I need to animate single contiguous code listings by showing and hiding parts of code using \onslide. However, TeX is complaining. How can I achieve this? I tried the advice here but it didn't work.

Minimum working sample:

\documentclass[utf8,pdf,aspectratio=169,handouts]{beamer}
\usepackage{listingsutf8}
\lstset{escapeinside={(*@}{@*)}}
\begin{document}

\begin{lstlisting}
Hello (*@ \onslide<2-> @*) world
\end{lstlisting}

\end{document}

1 Answers1

3

Your code seems to work fine, but as it's beamer you need a frame environment, and as this is verbatim text, you need the frame to be fragile, i.e.

\documentclass[utf8,pdf,aspectratio=169,handouts]{beamer}
\usepackage{listingsutf8}
\lstset{escapeinside={(*@}{@*)}}
\begin{document}

\begin{frame}[fragile]
\begin{lstlisting}
Hello (*@\onslide<2->@*)world
\end{lstlisting}
\end{frame}
\end{document}

I removed some spaces in the above code, but not before generating the screenshot below, so the code gives less space between the words.

enter image description here

Torbjørn T.
  • 206,688