# Splitting a float with code listings

Using the floats and listings packages, I have defined a float for code listings and a shortcut for using it as follows:

\usepackage{floats}
\usepackage{listings}

\newfloat{program}{tbphH}{lop}[section]
\floatname{program}{Program}

\newcommand{\codefrom}[2][Matlab]
{
\begin{program}[p]
\lstinputlisting[language=#1]{#2}
\caption{#2}
\label{#2}
\end{program}
}


Now, if a code file is too long, it will just continue down outside the page. Instead, I would like to automatically split the float at the end of the page, and continue on the next page.

Is there any way to accomplish this without sacrificing the float structure? If not, is there another way to get numbering etc as easily as with a float?

-
+1 since most of us will need this at some point – dank Oct 27 '10 at 9:42

As for doing numbering the way floats do I suppose you can wrap your own counter using \newcounter, \addtocounter{counter}{value} and \value{counter}.
 But how do I set the numbering to be within sections? Do I have to redefine the \section{} command to reset the counters, or is there some other, simpler way? – Tomas Lycken Nov 2 '10 at 21:12 This is what I ended up doing. For anyone else coming to look at this, \refstepcounter from the hyperref package is really useful for the counters. – Tomas Lycken Nov 12 '10 at 20:04