beamer add tag
samcarter
*(this recently came up in chat, but no question was asked, so I thought I'd post one myself)*

I have a minted code block in a beamer presentation. How to uncover it line by line?

```
\documentclass{beamer}

\usepackage{minted}

\begin{document}

\begin{frame}[fragile]
  \begin{minted}[autogobble]{latex}
    \documentclass{standalone}
    \usepackage{tikzducks,tikzlings}
    \begin{document}
    \begin{tikzpicture}
      \duck[]
    \end{tikzpicture}
    \end{document}
  \end{minted}
\end{frame}

\end{document}
```
Top Answer
F. Pantigny
You should have a look at the package `piton`. When you use the class Beamer, in an environment `{Piton}` of `piton`, you only have to use the usual syntax of Beamer (the commands `\uncover`, etc. or the environments `{uncoverenv}`, etc.) directly in the listing you want to format.

Exemple:

```
\documentclass{beamer}

\usepackage{piton}

\begin{document}

\begin{frame}[fragile]
\begin{Piton}
def arctan(x,n=10):
   """Compute the mathematical value of arctan(x)"""
\begin{uncoverenv}<2->
    if x < 0:
        return -arctan(-x) # recursive call
\end{uncoverenv}
\begin{uncoverenv}<3->
        elif x > 1: 
        return pi/2 - arctan(1/x) 
\end{uncoverenv}
\begin{uncoverenv}<4->
    else: 
        s = 0
        for k in range(n):
            s += (-1)**k/(2*k+1)*x**(2*k+1)
        return s 
\end{uncoverenv}
\end{Piton}
\end{frame}

\end{document}
```

The package `piton` requires the use of LuaLaTeX.
Answer #2
Qrr
Both `\pause` and `\onslide<…>` seem to work, the latter needs minted's `beameroverlays` option set as `<` and `>` are treated differently otherwise.

The first frame shows the first line of code only on the second slide,
the second frame does show the first line of code on the first slide.

```
\documentclass{beamer}
\usepackage{minted}
\usetheme{Madrid} % footline doesn't disappear?
\setminted{escapeinside=||}
\begin{document}

\begin{frame}[fragile]
\frametitle{With \string\pause}
\begin{minted}[autogobble]{latex}
  |\pause|\documentclass{standalone}
  |\pause|\usepackage{tikzducks,tikzlings}
  |\pause|\begin{document}
  |\pause|\begin{tikzpicture}
  |\pause|  \duck[]
  |\pause|\end{tikzpicture}
  |\pause|\end{document}
\end{minted}
\end{frame}

\begin{frame}[fragile]
\frametitle{With \string\onslide, needs \texttt{beameroverlays} set}
\setminted{beameroverlays}
\begin{minted}[autogobble]{latex}
  |\onslide<+->|\documentclass{standalone}
  |\onslide<+->|\usepackage{tikzducks,tikzlings}
  |\onslide<+->|\begin{document}
  |\onslide<+->|\begin{tikzpicture}
  |\onslide<+->|  \duck[]
  |\onslide<+->|\end{tikzpicture}
  |\onslide<+->|\end{document}
\end{minted}
\end{frame}
\end{document}
```
Answer #3
samcarter
One possible approach is to use the `tikzmark` library to cover up the future lines with a rectangle of the same colour as the background:

```
\documentclass{beamer}

\usepackage{minted}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\setminted{escapeinside=||}

\makeatletter
\def\slideinframe{\beamer@slideinframe}
\makeatother

\begin{document}

\begin{frame}[fragile]
  \begin{minted}[autogobble]{latex}
    |\tikzmark{start}|\documentclass{standalone}
    \usepackage{tikzducks,tikzlings}
    \begin{document}
    \begin{tikzpicture}
      \duck[]
    \end{tikzpicture}
    \end{document}|\hfill\tikzmark{stop}|
  \end{minted}
  \begin{tikzpicture}[remember picture,overlay]
  \fill[bg] ([yshift=-2pt+2\baselineskip-\slideinframe*\baselineskip]pic cs:start) rectangle ([yshift=-2pt]pic cs:stop);
  \end{tikzpicture}
  \pause[8]
\end{frame}

\end{document}
```

![document.gif](/image?hash=95ff48e31e0a57dcacd8f2b36f2f37db3e95f4f483ff993900e74503d11aefd7)


The same technique can also be used to hide specific lines on certain overlays:

```
\documentclass{beamer}

\usepackage{minted}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\setminted{escapeinside=||,linenos}

\newcommand<>{\coverlines}[2]{
  \begin{uncoverenv}#3
    \begin{tikzpicture}[remember picture,overlay]
      \fill[bg] ([yshift=-2pt+2\baselineskip-#1*\baselineskip]pic cs:start) rectangle ([xshift=\linewidth,yshift=-2pt+1\baselineskip-#2*\baselineskip]pic cs:start);
     \end{tikzpicture}
   \end{uncoverenv}
}

\begin{document}

\begin{frame}[fragile]
  \begin{minted}[autogobble]{latex}
    |\tikzmark{start}|\documentclass{standalone}
    \usepackage{tikzducks,tikzlings}
    \begin{document}
    \begin{tikzpicture}
      \duck[]
    \end{tikzpicture}
    \end{document}
  \end{minted}
  \coverlines<1>{2}{2}
  \coverlines<1>{4}{6}
  \coverlines<-2>{5}{5}
  \pause[3]
\end{frame}

\end{document}
```
![document.gif](/image?hash=aac8e9f65e1a7ab0738d0f5cbc9c21909c9b4216a6defaf01171a73e26cb8b03)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.