6

I'm trying to enclose Minted in a new environment as follows:

\documentclass{article}
\usepackage{minted}
\usepackage{mdframed}
\usepackage[varqu]{zi4}

\definecolor{codebggray}{rgb}{0.95,0.95,0.95}

\newenvironment{codeblock}[1]{%
  \begin{mdframed}[backgroundcolor=codebggray]
  \begin{minted}[fontfamily=zi4]{#1}
}{%
  \end{minted}
  \end{mdframed}
}

\begin{document}
\begin{codeblock}{python}
  colors    = ['b','g','r','c','m','y','k']
  linetypes = ['-','--','-.',':']
  linestyle = itertools.product(colors,linetypes)
\end{codeblock}
\end{document}

Problem is, when I try to compiled this, I get:

) (./bob.pyg) (/usr/local/texlive/2014/texmf-dist/tex/latex/upquote/upquote.sty
)
! FancyVerb Error:
  Extraneous input ` ' between \begin{minted}[<key=value>] and line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}

l.17 \begin{codeblock}{python}

!  ==> Fatal error occurred, no output PDF file produced!

What gives?

4

To easily define your new environment, you could use \newtcblisting from the powerful tcolorbox package and the fact that it cooperates with minted:

\documentclass{article}
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{minted}

\definecolor{codebggray}{rgb}{0.95,0.95,0.95}

\newtcblisting{codeblock}[2][]{%
  colback=codebggray,
  listing only,
  minted options={
    fontsize=\small
  },  
  minted language=#2,
  #1
}

\begin{document}

\begin{codeblock}{python}
  colors    = ['b','g','r','c','m','y','k']
  linetypes = ['-','--','-.',':']
  linestyle = itertools.product(colors,linetypes)
\end{codeblock}

\end{document}

The result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.