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 – samcarter Sep 14 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. – samcarter Sep 14 at 13:07
up vote 4 down vote accepted

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.