# workaround for minted environments in in Beamer notes

A work around for adding code to beamer notes is described here: LaTeX beamer: Code listings in notes. Here is how I've adapted it for use with Minted:

\documentclass{beamer}
\setbeameroption{show notes}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]
\begin{minted}{text}
Qux
\end{minted}

Goodbye.\note{hello}
\end{frame}

\newsavebox{\LstA}
\begin{lrbox}{\LstA}
\begin{minted}{text}
foo bar
\end{minted}
\end{lrbox}

\begin{frame}[fragile]
second frame
\note{Here is some code in a note:
\usebox{\LstA}}
\end{frame}

\end{document}


I get the following error:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

l.1 \begin{Verbatim}[commandchars=\\\{\}]

If I keep pressing ENTER, a PDF does build that seems to have the right contents - but could the errors be made to go away?

• related feature request: github.com/josephwright/beamer/issues/496 – user36296 Sep 14 '18 at 13:06
• If your document compiles with an error, don't look at the broken output which might or might not be a valid pdf file. After an error, Tex only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error. – user36296 Sep 14 '18 at 13:07

In order to set the minted environment in the horizontal box created by lrbox you need to recustom Verbatim to be BVerbatim:

\documentclass{beamer}
\setbeameroption{show notes}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]
\begin{minted}{text}
Qux
\end{minted}

Goodbye.\note{hello}
\end{frame}

\newsavebox{\LstA}
\begin{lrbox}{\LstA}
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}%
\begin{minted}{text}
foo bar
\end{minted}
\end{lrbox}

\begin{frame}[fragile]
second frame
\note{Here is some code in a note:
\usebox{\LstA}}
\end{frame}

\end{document}


The trick is used in line 987 of minted.sty for mintinline.

You can define a Bminted environment:

\documentclass{beamer}
\setbeameroption{show notes}
\usepackage{minted}

\newenvironment{Bminted}[2][]
{\VerbatimEnvironment
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}%
\begin{minted}[#1]{#2}}
{\end{minted}}

\begin{document}

\begin{frame}[fragile]
\begin{minted}{text}
Qux
\end{minted}

Goodbye.\note{hello}
\end{frame}

\newsavebox{\LstA}
\begin{lrbox}{\LstA}
\begin{Bminted}[showspaces]{text}
foo bar
\end{Bminted}
\end{lrbox}

\begin{frame}[fragile]
second frame
\note{Here is some code in a note:
\usebox{\LstA}}
\end{frame}

\end{document}


I added the showspaces option just by way of example, in order to make sure that minted options are honored.