# Tcolorbox + minted source code listing that works in beamer

I copied and modified the code snippet in the accepted answer here to highlight cpp code:

\usepackage{tcolorbox}
\tcbuselibrary{minted,skins}

\newtcblisting{cppcode}[1][]{
listing engine=minted,
colback=bg,
colframe=black!70,
listing only,
minted style=colorful,
minted language=cpp,
minted options={linenos=true,numbersep=3mm,texcl=true,#1},
left=5mm,enhanced,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}}
}
\definecolor{bg}{rgb}{0.85,0.85,0.85}


Then, I use it in a Beamer frame like this:

\begin{frame}[fragile]
\frametitle{Title}
\framesubtitle{Subtitle}

\begin{cppcode}
int main() {
int x, y;
}
\end{cppcode}

\end{frame}


However, only an empty box with a gray margin shows up, with no code in it.

I have the following beamer class and theme:

\documentclass[xcolor=table]{beamer}

\usetheme{CambridgeUS}
\usecolortheme{beaver}


How can I make a similar tcolorbox code listing show up in beamer? Ideally, I would also like it to be breakable across frames.

Update: the author suggested in a comment to change the name of bg. I changed it to bgg, and now the background is also (a lighter) gray, but the code still does not show up.

• Be sure to run pdflatex with the -shell-escape option – egreg Jul 8 '16 at 16:48

It turns out that the name bg for the background color conflicts with beamer. Just name it to something else

\newtcblisting{cppcode}[1][]{
listing engine=minted,
colback=cppcodebg,
colframe=black!70,
listing only,
minted style=colorful,
minted language=cpp,
minted options={linenos=true,numbersep=3mm,texcl=true,#1},
left=5mm,enhanced,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}}
}
\definecolor{cppcodebg}{rgb}{0.85,0.85,0.85}


Minimal example, to be run with

pdflatex -shell-escape test


or minted can not run pygmentize:

\documentclass{beamer}

\usepackage{tcolorbox}
\tcbuselibrary{minted,skins}

\newtcblisting{cppcode}[1][]{
listing engine=minted,
colback=cppcodebg,
colframe=black!70,
listing only,
minted style=colorful,
minted language=cpp,
minted options={linenos=true,numbersep=3mm,texcl=true,#1},
left=5mm,enhanced,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}}
}
\definecolor{cppcodebg}{rgb}{0.85,0.85,0.85}

\begin{document}

\begin{frame}[fragile]
\frametitle{Title}
\framesubtitle{Subtitle}

\begin{cppcode}
int main() {
int x, y;
}
\end{cppcode}

\end{frame}

\end{document}

• I am not sure what I did, I didn't seem to change anything, just kept recompiling, it gave the result mentioned in my update before, but now I get, for the command: pdflatex.exe --shell-escape -synctex=1 -interaction=nonstopmode "prezentare".tex the error message Package minted Error: Missing Pygments output; \inputminted wasor may be using the kpsewhich option without having PowerShell installed. \end{cppcode}. If I use \begin{minted}{cpp}, it compiles fine... – IVlad Jul 8 '16 at 16:58
• The error is at the line \end{cppcode} in prezentare.vrb. – IVlad Jul 8 '16 at 17:02
• @IVlad Sorry, can't check with Windows – egreg Jul 8 '16 at 17:04