How can I move floats that aren't tables or figures to the end of a document (endfloat for listings)?

I think, I have found a possible solution

First some explanation:

\DeclareDelayedFloat{⟨float⟩}[⟨file extension⟩]{⟨heading⟩}

This command from endfloat package prepares the package for floating environments other than standard figure or table, say for example

\DeclareDelayedFloat{exercise}{fexe}{List of Exercises}

It requires (see lines 350 and following of endfloat.sty) that there is a listofexercises command.

Well, this is the point where

\DeclaredDelayedFloat{lstlisting}{flol}{List of Listings}

fails:

There is no \listoflstlistings command ;-)

It is called lstlistoflistings instead. The clue is just to say

\newcommand\listoflstlistings}{\lstlistoflistings}%

\documentclass[12pt]{book}

\usepackage{listings}
\usepackage{blindtext} % Just for dummy content
% use \usepackage[nomarkers]{endfloat} to drop the markers in the text
\usepackage{endfloat}  

%%% \DeclareDelayedFloat looks for the \listoflstlistings command
%%% since it is assumed, that there is an associate command for the list of listings
%%% 'environment' lstlistings as given to \DeclareDelayedFloat ---> listoflstlistings.
%%% However, `listings` uses \lstlistoflistings, so define this new command
%%% to make \DeclareDelayedFloat happy. 
\newcommand{\listoflstlistings}{\lstlistoflistings}%

% Change `List of Listings` as third argument at will.
\DeclareDelayedFloat{lstlisting}[flol]{\textbf{List of Listings}}

\begin{document}

\chapter{First content}


\blindtext

\begin{lstlisting}[language=C,float=t,caption={Hello World - a famous example}]
#include <stdio.h>

int main(int argc, char **argv)
{
  printf("Hello World\n");
  return(EXIT_SUCCESS);
}
\end{lstlisting}

\blindtext

\begin{lstlisting}[language=C++,float=t,caption={Hello World - a famous example, again}]
#include <iostream>

int main(int argc, char **argv)
{
  cout << "Hello World" << std::endl;
  return(EXIT_SUCCESS);
}
\end{lstlisting}

\end{document}

enter image description here

And if you are now confused about \listof and \lstlisting, \listoflstlistings ... I know, what you mean ;-)

File versions:

Endfloat:

\def\filename{endfloat}
\def\fileversion{v2.5d}
\def\filedate{2011/12/25}
\def\docdate{2011/12/05}

Listings:

\def\filedate{2014/03/04}
\def\fileversion{1.5c}

So, listings is quite new.


Christians solution is great when relying on the float commands of lstlisting.

But I wanted to use the caption and float package to change all of my floats. Tables, Figures, Listings the whole shebang.

So based on this and Christians brilliant find I came up with the following:

\documentclass[12pt]{scrbook}

\usepackage{listings}
\usepackage{blindtext} % Just for dummy content
\usepackage{endfloat}  
\usepackage{tocloft}
\usepackage{float}

%%% Declare new float environment for Listings
\newcommand{\listofsnippetname}{List of Listings}
\newlistof{snippet}{lol}{\listofsnippetname}
\newfloat{snippet}{thp}{lol}[chapter]
\floatname{snippet}{Listing}
\newcommand{\snippetautorefname}{Listing}
\renewcommand{\thesnippet}{\thechapter.\arabic{snippet}}

%%% \DeclareDelayedFloat looks for the \listofsnippets command
\newcommand{\listofsnippets}{\listofsnippet}

%%% This makes endfloat aware of the snippet floats
\DeclareDelayedFloat{snippet}[flol]{List of Listings}

\begin{document}

\chapter{First content}

\blindtext

\begin{snippet}
\begin{lstlisting}[language=C]
#include <stdio.h>

int main(int argc, char **argv)
{
  printf("Hello World\n");
    return(EXIT_SUCCESS);
    }
\end{lstlisting}
\caption[Hello World]{The usual example.}
\label{lst:helloworld}
\end{snippet}

\end{document}