minted
minted copied to clipboard
First paragraph after minted listing is indented
If you put a listing with a minted environment or inputminted between a section header and a paragraph, that first paragraph is indented which should not happen (At least it doesn't if you use includegraphics with figure or tabular with table).
Example:
\documentclass{article}
\usepackage{minted}
\begin{document}
\section{About trees}
\begin{listing}
\begin{minted}{java}
public static void main(String[] args) {
System.out.println("Whatever...");
}
\end{minted}
\caption{A listing}
\end{listing}
Some trees have big leaves while others have small ones.
There are also trees that have needles.
\end{document}
I've compared this with the figure
environment, and it is a bug. The figure
and listing
environments have exactly analogous definitions when the newfloat
package option is used (and there's still the extra indent), so this appears to be the result of something that happens within the minted
environment itself. I'll have to dig into the definitions to see if I can figure out what's happening.
fancyverb's listing environment unconditionally sets the global flag \if@nobreak
to false which seems wrong, but anyway as this is global, if it is set at all it should be saved and restored "by hand" . Not sure quite where this should be fixed: fancyverb, fvextra, minted... but adding the save/restore to the document suppresses the indentation
\documentclass{article}
\usepackage{minted}
\begin{document}
\makeatletter
\section{About trees}
\global\let\zzz\if@nobreak
\begin{listing}
\begin{minted}{java}
public static void main(String[] args) {
System.out.println("Whatever...");
}
\end{minted}
\caption{A listing}
\end{listing}
\global\let\if@nobreak\zzz
Some trees have big leaves while others have small ones.
There are also trees that have needles.
\end{document}