4

Is it possible to remove the spacing below the code of a minted environment? When I have a block of code underneath another it doesn't produce any spacing (which is what I want), but it does for text (which I don't want). Is there somthing similar like belowskip of the listings package that I can use as a global option?

\documentclass{article}

\usepackage{minted}

\begin{document}

\newminted{python3}{linenos=true} % belowskip=0pt?

\begin{python3code}
print("Hello world")
\end{python3code}

Some text

\end{document}
pg-robban
  • 803

1 Answers1

6

minted uses the package fancyvrb to create the environment. fancyvrb uses a modification of trivlist. So you can have to modify the trivlist.

One possibility is shown below. Here I created a new key belowskip.

EDIT

In combination width \newminted it also works (see comment below):

% pdflatex --shell-escape 
\documentclass{article}

\usepackage{minted}
\makeatletter
\newlength\minted@belowskip
\define@key{minted@opt}{belowskip}[\@topsepadd]
{\setlength{\minted@belowskip}{#1}}

\def\minted@endparenv{%
  \addpenalty\@endparpenalty\addvspace\minted@belowskip\@endpetrue}
\def\FV@EndList{%
  \FV@ListProcessLastLine
  \FV@EndListFrame
  \minted@endparenv
  \endgroup
  \@endpetrue}
\makeatother
\newminted{python3}{linenos=true, belowskip=4cm}
\begin{document}

\begin{python3code}
print("Hello world")
\end{python3code}

Some text


\begin{python3code}
print("Hello world")
\end{python3code}

Some text

\end{document}

Orig

% pdflatex --shell-escape 
\documentclass{article}

\usepackage{minted}
\makeatletter
\newlength\minted@belowskip
\define@key{minted@opt}{belowskip}[\@topsepadd]
{\setlength{\minted@belowskip}{#1}}

\def\minted@endparenv{%
  \addpenalty\@endparpenalty\addvspace\minted@belowskip\@endpetrue}
\def\FV@EndList{%
  \FV@ListProcessLastLine
  \FV@EndListFrame
  \minted@endparenv
  \endgroup
  \@endpetrue}
\makeatother
\begin{document}

\begin{minted}[belowskip=4cm]{python}
print("Hello world")
\end{minted}

Some text


\begin{minted}[belowskip=0pt]{python}
print("Hello world")
\end{minted}

Some text

\end{document}
Marco Daniel
  • 95,681
  • Seems to break if I use it as an option in my environment:

    `\newminted{python3}{linenos=true, belowskip=0pt}

    \begin{python3code} ... `

    – pg-robban Dec 04 '11 at 20:28
  • @pg-robban: It works also with \newmindet. – Marco Daniel Dec 04 '11 at 20:53
  • Must be a conflict with the other packages I'm using: package calc error 'xkv@tempa@toks' invalid at this point. But the MWE seems to be working so I'll accept this answer. Thank you! – pg-robban Dec 04 '11 at 21:13
  • I believe that calc is loaded by minted itself. I can't from that output what the conflict is. But if you wanted to track it down, you could probably use just calc with whatever your other packages are to minimize the bug. – Jason Hemann Mar 17 '18 at 20:09