This is related to the question How to space before and after a `minted` code block with bgcolor? There it is explained that there is a bug with minted which causes the space above and below a code block to disappear when you set a background colour. A fix is given for the minted environment. I want to fix the \inputminted command as well! Unfortunately the same fix doesn't work as this is a command not an environment.

I thought I could fix it with \apptocmd and \pretocmd, but as the following minimal working example shows, \pretocmd does the right thing but \apptocmb gives the error "! Missing \endcsname inserted."



% The following line doesn't work

% These are the fixes given for the minted environment


n = 20
for i in range(n)
    print("Hello World")


% Here is where the problem lies.


% This bit of code works as it should
n = 10
for i in range(n)
    print("Hello World")


1 Answer 1


The \inputminted command is defined with an optional argument, so it's not patchable with etoolbox, unless you say


(see How can I use \patchcmd with commands with optional arguments?)

The package xpatch does the necessary bits by itself.


enter image description here

You must log in to answer this question.

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