I want to conditionally load minted and define an environment, but after using IfFileExists I'm running into an error:
FancyVerb Error:
Extraneous input `resetoptions \setkeys {minted@opt}{frame=single} \begin {fi
gure}[htp] \centering \begin {minipage}{9cm} \begin {VerbatimOut}{\jobname .pyg
}' between \begin{Rcode}[<key=value>] and line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}
l.35 \begin{Rcode}
The solution for embedding the minted environment inside another came from here.
The code I'm running is shown below:
\documentclass{article}
\usepackage{xcolor}
\IfFileExists{minted.sty}{
\usepackage{minted}
\usepackage{pgfkeys}
\pgfkeys{
/terminal/.cd,
caption/.code={\pgfkeyssetvalue{terminal/caption}{\caption{##1}}},
label/.code={\pgfkeyssetvalue{terminal/label}{\label{##1}}},
}
\pgfkeyssetvalue{terminal/label}{}
\pgfkeyssetvalue{terminal/caption}{\caption{}}
\makeatletter
\newenvironment{Rcode}{%
\VerbatimEnvironment
\minted@resetoptions
\setkeys{minted@opt}{frame=single}
\begin{figure}[htp]
\centering
\begin{minipage}{9cm}
\begin{VerbatimOut}{\jobname.pyg}}
{%
\end{VerbatimOut}
\minted@pygmentize{r}
\DeleteFile{\jobname.pyg}
\end{minipage}
\end{figure}}
\makeatother
}{}
\begin{document}
\begin{Rcode}
# Als je specifieke elementen wil aanhalen gebruik dan
c(1,2,3,7,10,15)
# Voor een rij van elementen gebruik
1:15
\end{Rcode}
\end{document}
@-command before using them. Since those commands are in the argument to\IfFileExists, you need to have\makeatletterbefore the argument is grabbed. – egreg May 15 '14 at 12:20