# How to use verbatim with tcolorbox?

The following gives many strange errors:

\begin{tcolorbox}[fit,height=5cm,blank, borderline={1pt}{-2pt},nobeforeafter]
\begin{verbatim}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{verbatim}
\end{tcolorbox}


including "Missing \$ inserted", "Double subscript", so verbatim isn't working. Without tcolorbox the code works fine. How can I use verbatim with tcolorbox?

• For those of us who may not be very familiar with tcolorbox, can you include a complete document (starting with \documentclass and ending with \end{document})? For example, with some experimentation I was able to reproduce your error with \usepackage{tcolorbox} \tcbuselibrary{fitting} \tcbuselibrary{skins} but I don't know if you did the same things. – ShreevatsaR Feb 7 '18 at 2:45
• Please also provide the full and exact text of the error message you get when compiling the (completed) code you provide. This will include, for example, the line number corresponding to the relevant line in your example. – cfr Feb 7 '18 at 2:48
• Section '7 Saving and Loading of Verbatim Texts'. Page 126 of tcolorbox's manual. 22.1 /tcb/verbatim page 423. – cfr Feb 7 '18 at 2:53

It runs. I hope the options are what you intended.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{fitting,skins}
\usepackage{listings}

\newsavebox{\tempbox}

\begin{document}
\setbox\tempbox=\hbox{\begin{lstlisting}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{lstlisting}}

\begin{tcolorbox}[fit,height=5cm,blank, borderline={1pt}{-2pt},nobeforeafter]
\usebox\tempbox
\end{tcolorbox}

\end{document}