3

I'm using the minted-package to color code in a paper I'm writing. In order to change the style of the parts where my code will be displayed later down the road I defined a new enviroment. However, LaTeX somehow doesn't want to work with it.

Here's what I wrote:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}

\newenvironment{pythoncode}[0]{\begin{minted}{python}}{\end{minted}}

\begin{document}

\begin{pythoncode}
from foo import bar
\end{pythoncode}

\end{document}

But it doesn't work. Latex throws an error:

File ended while scanning use of \FancyVerbGetLine. \par <*> bib.tex

I suspect you have forgotten a '}', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type 'E' or 'X' now and fix your file.

! Emergency stop. <*> foo.tex

*** (job aborted, no legal \end found)

No pdf is produced after that. I tried highliting the code without \newenvironment (just using \begin{minted}{python} right inside the document), it works perfectly fine.

What am I doing wrong?? There is no } missing, is there?

I'm using pdflatex on sharelatex.com.

1
  • 1
    I think this is the verbatim content of minted -- it doesn't see \end{minted} correctly then.
    – user31729
    Oct 11, 2015 at 9:45

1 Answer 1

2

What you are doing is not the proper way to define an alias for minted environment.

You can use newminted like

\newminted{python}{linenos}

and then use pythoncode environment.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}

\newminted{python}{linenos}

\begin{document}

\begin{pythoncode}
from foo import bar
\end{pythoncode}

%% above one is equivalent to the following
\begin{minted}[linenos]{python}
from foo import bar
\end{minted}

\end{document}

enter image description here

2
  • Ah, that's great! Thanks! However, maybe you want point in your answer that the environment pythoncode is created automatically after the command \newminted{python}{linenos} is executed - I've had some trouble connecting that. But thanks! I works now.
    – Nearoo
    Oct 11, 2015 at 10:35
  • @Nearoo Once you say \newminted{python}{linenos} the pythoncode environment becomes available. Similarly if you say \newminted{cpp}{linenos} cppcode becomes available and hence forth.
    – user11232
    Oct 11, 2015 at 10:39

You must log in to answer this question.

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