Frames for minted in beamer

beamerminted

I ran into a problem of including a tex file via \inputminted from the minted package. When I try to add a frame around the code with frame=single I get lots of errors referring to missing $'s missing }'s and missing \item's.

The MWE is a self-referential tex-file with the following contents:

% this is: frames_for_minted_in_beamer.tex
\documentclass{beamer}

\usepackage{minted}

\begin{document}
\begin{frame}[fragile]
    \inputminted[%
        label=frames_for_minted_in_beamer.tex,%
        % frame=single,% this does not work
    ]{latex}{./frames_for_minted_in_beamer.tex}
\end{frame}
\end{document}

What went wrong here?

Ty for any help,
Franz

Best Answer

The problem are the special characters you use in the label. Using the frame=single style will typeset the label at the top and unescaped math characters like _ will cause an error.

You can either escape them:

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}

% this is: frames_for_minted_in_beamer.tex
\documentclass{beamer}

\usepackage{minted}

\begin{document}
\begin{frame}[fragile]
    \inputminted[%
        label=frames\_for\_minted\_in\_beamer.tex,%
        frame=single,% this does not work
    ]{latex}{test.tex}
\end{frame}
\end{document}

or use the tcolorbox package to draw a simple frame without the label:

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}

\documentclass{beamer}

\usepackage[most]{tcolorbox}
\tcbuselibrary{minted}
\tcbset{listing engine=minted,colback=white,sharp corners}

\begin{document}
\begin{frame}[fragile=singleslide]
\tcbinputlisting{minted language=latex,listing file=test.tex,label=test}
\end{frame}
\end{document}