The MWE below aims to color the text and background of a Verbatim
environment.
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{color}
\usepackage{calc}
\definecolor{PYtxt}{rgb}{0.97,0.97,0.95}
\definecolor{PYbgc}{rgb}{0.15,0.16,0.13}
\newsavebox{\PYbgbox}
\newenvironment{PYcolorbox}%
{\noindent%
\begin{lrbox}{\PYbgbox}%
\begin{minipage}{\linewidth-2\fboxsep}%
\color{PYtxt}}%
{\ignorespacesafterend%
\end{minipage}%
\end{lrbox}%
\colorbox{PYbgc}{\usebox{\PYbgbox}}}
\begin{document}
\begin{PYcolorbox}
\begin{Verbatim}[commandchars=\\\{\},numbers=left,firstnumber=1,stepnumber=1]
File "<stdin>", line 1
1+
^
SyntaxError: invalid syntax
\end{Verbatim}
\end{PYcolorbox}
\end{document}
The problem with the code above is that line numbers produced by fancyvrb
are also colored white, and cannot be seen when compiled.
How may I do both of the following (but not at the same time):
- independently change the text color and line number color?
- expand
PYcolorbox
to the left to include the (white) line numbers?
Alternative code method: adding formatcom=\color{white}
to the Verbatim
arguments yields white text (including line numbers), but also affects the bottom margin of the color background.
The goal would be to use this in tandem with Pygments
.
Any help would be appreciated.