I want to include part of the following file, foo.py, using \inputminted in a listing environment.
def foo(a, b):
return a + b
def bar(a, b)
return a - b
However, if this listing environment occurs in some other environment that increases the indentation of the left margin, \inputminted does not seem to respect this.
(Note that you'll need to save the contents of the first code block as foo.py in the same directory as this MWE in order for it to compile.)
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{enumerate}
\item
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse euismod, orci ac iaculis posuere, felis augue ultricies augue.
\begin{listing}[H]
\inputminted[firstline=1,lastline=2]{python}{foo.py}
\caption{The function foo}
\end{listing}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse euismod, orci ac iaculis posuere, felis augue ultricies augue.
\begin{listing}[H]
\begin{minted}{python}
def foo(a, b):
return a + b
\end{minted}
\caption{The function foo}
\end{listing}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse euismod, orci ac iaculis posuere, felis augue ultricies augue.
\end{enumerate}
\end{document}
I believe this is related to Centering \inputminted inside a figure?, but I'm not totally sure what the solution is. According to the fancyvrb documentation, resetmargins is false by default, so the margin should not have been reset, but it nonetheless appears to have been reset. How can I make sure that the margin respects other indented environments when using \inputminted inside of a listing environment? That is, I want to be able to use \inputminted but have the indentation of the code block that I get for the second listing environment when just using \begin{minted}...\end{minted}.


Package minted Error: Missing Pygments output; \inputminted was [...ed[firstline=1,lastline=2]{python}{foo.py}]. – Sebastiano Oct 26 '19 at 20:13foo.py. I'll edit the question to make that clearer. – Adam Liter Oct 26 '19 at 20:37