# Usage of minted inside newenvironment in minted 2.0a³

As a followup question to Lstinline macro inside another environment, I kind of want to do the same thing for minted as well, but I'm held back by the following:

I used the code from Using minted to define a new environment but that doesn't seem to work so well for the latest version of minted (version 2.0 alpha 3). \mintinline works nicely in the latest version. Preferrably I wouldn't want to choose between the two.

Any known workaround to this?

\documentclass[10pt]{article}
\makeatletter
\IfFileExists{minted.sty}{%
\usepackage{minted}
\usemintedstyle{euryris}
\usepackage{lineno}
\def\gobble##1{}
\renewcommand\DeleteFile[1]{}
\newenvironment{MyEnvironment}{% works fine in v1.7 ?
\VerbatimEnvironment
\minted@resetoptions
\setkeys{minted@opt}{}
\begin{center}
\begin{minipage}{\linewidth}
\begin{VerbatimOut}{\jobname.pyg}}
{%
\end{VerbatimOut}
\minted@pygmentize{python}
\DeleteFile{\jobname.pyg}
\end{minipage}
\end{center}}
}{}
\makeatother
\begin{document}

\section{Environment}
Have some python code:
\begin{MyEnvironment}
print(x**2)
\end{MyEnvironment}
...as the pleasure is all mine.

\section{Inline code}
Some serious inline code right here:~\mintinline{python}{print(x**2)}. Some seriously ugly \jobname.pyg to the right % works fine in v2.0 ?
\end{document}


I'm also looking to embed \mintinline inside another macro. Not sure if the same recipe as lstinline applies?

Depending on what you are doing, you may want to take a look at the \newminted and \newmintinline macros. These allow you to create custom versions with your own default arguments.

If you do need to create your own environment containing minted, this works and is simpler, since it doesn't get into the minted internals:

\newenvironment{MyEnvironment}{%
\VerbatimEnvironment
\begin{center}%
\begin{minipage}{\linewidth}%
\begin{minted}{python}}
{%
\end{minted}%
\end{minipage}%
\end{center}}


The minipage and center won't necessarily be needed, depending on your final objective.

You should be able to treat \mintinline like you would \lstinline without any trouble. Also, in most situations you should be able to treat it just like any other macro, so long as you aren't using the # and % characters.