I'm trying to make an environment for python code using minted
, but I always get FancyVerb error
. Here is my code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\newenvironment{code}[1][python]
{
\begin{table}[ht]
\begin{tabular}{p{0.8\textwidth}}
\rowcolor{Gray}
\begin{minted}{#1}
}
{
\end{minted}
\end{tabular}
\end{table}
}
\begin{document}
\begin{code}
print("This is some code example")
\end{code}
\end{document}
I read in this this answer that this is a problem with this kind of package, which cannot be used with \newenvironment
. Is there any way around this? I don't mind changing the approach completely, but the result I want is to be able to have a code environment that formats the text according to the desired language (in my case python, but preferably I would like to be able to reuse this for other languages too).