I want to create a listing using minted
that has background colour and can be split across pages. The usual advice in that case is to use the mdframed
environment and I have written a command that follows this advice
\newcommand{\clojurecode}[4]{
\label{code:#2}
\begin{mdframed}[backgroundcolor=LightGray,hidealllines=true,leftmargin=10mm]
\clojurefile{#1}
\end{mdframed}
\captionof{code}[#3]
{#4}
}
But in that case I can't seem to be able to easily specify that I want the caption to be kept on the same page the listing is on and the samepage
environment would keep the listing from splitting across the pages, which is not what I want.
Is there any solution to tie the caption to the bottom the the listing so they always appear on the same page that none the less lets the listing break?
EDIT:
\clojurefile
command is generated with this \newmintedfile
call:
\newmintedfile{clojure}{framesep=2mm,
baselinestretch=1.2,
numbersep=16pt,
fontsize=\footnotesize,
linenos,
breaklines,
breakanywhere}
EDIT2: I made a minimal example to demonstrate what's wrong: https://gist.github.com/jaen/68c6fe78c83d5d58721f
Ch1 is a good behaviour - minted breaks, caption starts next to listing end,
Ch2 is with samepage and behaves wrongly - minted doesn't break (though captions starts where it should),
Ch3 has longer code - minted breaks as I expected, but the caption is pushed to the next page and does not start immediately afterthe listing,
Ch4 is samepage again - it both doesn't let minted break and pushes the caption to the next page,
Ch5 is a longer code sample still - again minted breaks, but the caption is pushed to the next page,
Ch6 is samepage and commented out, because if you uncomment it, it won't even compile,seems it enters an infinite loop of trying to fit the code + caption on one page and it can't.
What I want is to get a behaviour where a) minted breaks across pages, b) the caption always starts next to the end of the listing and is not pushed to the next page.
And I can't seem to find one. Anyone?
tcolorbox
? (Just a guess – I haven't actually tried it.tcolorboy
has aminted
library for integratedminted
support, though…)