minted icon indicating copy to clipboard operation
minted copied to clipboard

First paragraph after minted listing is indented

Open D4Muck opened this issue 6 years ago • 2 comments

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}

screenshot from 2017-12-28 12-46-26

D4Muck avatar Dec 28 '17 11:12 D4Muck

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.

gpoore avatar Jan 03 '18 01:01 gpoore

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}

davidcarlisle avatar Jan 03 '18 01:01 davidcarlisle