This question is similar to Using Beamer to step through an algorithm written in pseudocode. but not tied to any particular environment. I prefer minted, but any other similar environment that can accomplish what I want is acceptable.
I want to step through an algorithm in beamer on a two-column frame. The left column should highlight the current line and the right column should show the execution state. MWE:
\documentclass{beamer}
\usepackage{minted}
\setminted[python]{autogobble}
\begin{document}
\begin{frame}[fragile]{Running code}
\begin{columns}
\begin{column}{0.50\textwidth}
\begin{overprint}
\onslide<1>
\begin{minted}[highlightlines={1}]{python}
N = 5
i = 0
lst = []
while i < N:
lst.append(i)
i = i + 1
\end{minted}
\onslide<2>
\begin{minted}[highlightlines={2}]{python}
N = 5
i = 0
lst = []
while i < N:
lst.append(i)
i = i + 1
\end{minted}
\onslide<3>
\begin{minted}[highlightlines={3}]{python}
N = 5
i = 0
lst = []
while i < N:
lst.append(i)
i = i + 1
\end{minted}
\onslide<4>
\begin{minted}[highlightlines={4}]{python}
N = 5
i = 0
lst = []
while i < N:
lst.append(i)
i = i + 1
\end{minted}
\end{overprint}
\end{column}
\begin{column}{0.50\textwidth}
Defined variables here and explanations of the highlighted line,
etc.
\end{column}
\end{columns}
\end{frame}
\end{document}
While the above method "works", it is unpractical because it causes way too much code bloat. Is there a better method? Something like this would be nice:
\begin{minted}[highlighted_line_on_beamer_slide={1,2,3,4,5,6,4,5,6,4,5,6}]{python}
N = 5
i = 0
lst = []
while i < N:
lst.append(i)
i = i + 1
\end{minted}


\againframeworks for this purpose since the execution state will be different the next time a particular line in a loop is executed. – Stand with Gaza Feb 16 '23 at 14:47