3

I am trying hard to create an environment for my source code. Here's my current state

\documentclass[a4paper,fontsize=12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{beton,euler}
\usepackage[english]{babel}


\usepackage{minted}
\usepackage{xcolor}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\newminted{python3}{bgcolor=bg, tabsize=4}

\newenvironment{sourcecode}[1]
{
    \def\savedcaption{\caption{#1}}
    \begin{listing}[ht]
    \begin{python3code}
}
{
    \end{python3code}
    \savedcaption
    \end{listing}
}

\title{Research}

\author{Me}

\date{\today}

\begin{document}
\maketitle
\begin{sourcecode}{"Hello"}
print("Hello")
\end{sourcecode}

\end{document}

I get fancyVerbErrors. I am lost. Any help would be very appreciated

1
  • 1
    Please post a complete example that we can run to get the errors, a fragment is not so useful, Commented Jan 26, 2016 at 12:43

1 Answer 1

5

This should do what you want.

\newenvironment{sourcecode}[1]
{%
    \VerbatimEnvironment
    \def\savedcaption{\caption{#1}}%
    \begin{listing}[ht]%
    \begin{python3code}%
}
{%
    \end{python3code}%
    \savedcaption
    \end{listing}%
}

You need \VerbatimEnvironment, because you are creating an environment that uses fancyvrb internally. You need a % after \begin{python3code} to prevent the newline that follows it from being treated as a space and triggering a fancyvrb error.

1
  • @tschm I just added a note on this to the documentation for the next version of minted, so it should be easier to find in the future.
    – G. Poore
    Commented Jan 26, 2016 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .