# endfloat, float - use with newfloat types

Does anyone know how I can get the the endfloat package to work with new float types defined using \newfloat (float package), for example:

\newfloat{map}{htbp}{lom}
\floatname{map}{Map}
\restylefloat*{map}

\newfloat{photo}{htbp}{lop}
\floatname{photo}{Photo}

-
Welcome to TeX.SE. It is always best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Nov 16 '11 at 2:37
Are you including \usepackage{float} in the preamble as I believe that is what defines \newlfoat. –  Peter Grill Nov 16 '11 at 2:39
Do you also have figures and tables in your document? If not, it should be possible. If so, do you want everything to go to the end (maps, photos, figures and tables)? –  Werner Nov 16 '11 at 3:09
Yes I am uncluding \usepackage{float} and yes I am actually using figures (no tables though) –  David Nov 16 '11 at 11:17

You need to include \usepackge{float} in order to be able to use \newfloat.

But, from the documentation it looks like the endfloat package only works with figures and tables as it explicitly looks for this name:

Because of how the redefinitions of figure and table are actually implemented, it is crucial that these environment names be used. That is, you cannot simply define a new environment which calls figure or table since the former must look for the literal string

That being said you could adapt what \endlfoat does to also handle the photo and map type floats (in addition to the usual figure and table). Below I have adapted it to include the photo float. You can further enhance this to also handle the map float by copying it and replacing every occurrence of photo with map and ppp with mmm (this is the extension of the .aux file that gets used).

A longer term solution would be to adapt the code in endfloat to be able to handle any type of float, but this should suffice for now.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{endfloat}

\newcommand{\lipsum}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. In malesuada consequat mollis. Duis viverra vestibulum quam id vehicula. Donec vel tellus a orci adipiscing euismod. Suspendisse lacinia metus lorem. Vivamus pellentesque, lacus quis blandit tincidunt, elit nunc ullamcorper enim, ut laoreet metus risus sed neque. Sed ac nibh ante, pellentesque vehicula sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel libero leo. Donec aliquam placerat arcu, et ultrices leo semper et. Curabitur dignissim, eros vitae dignissim porta, velit arcu vehicula tortor, vel blandit sapien magna in risus.}%

\newfloat{map}{htbp}{lom}
\floatname{map}{Map}
\restylefloat*{map}

\newfloat{photo}{htbp}{lop}
\floatname{photo}{Photo}

\makeatletter
\newif\if@photolist                %

\@photolistfalse

\def\listofphotos{\@empty}
\newcounter{postphoto}
\efloat@newwrite{ppp}
\ef@newct{ppp}

\providecommand{\photoname}{Photo}
\newcommand{\photoplace}{%
\begin{center}
\end{center}}

\let\@bphoto\photo
\def\photo{%
\efloat@condopen{ppp}
\efloat@iwrite{ppp}{\string\begin{photo*}}%
\if@domarkers%
\photoplace%
\fi%
\def\@currenvir{efloat@float}%
\begingroup%
\let\do\ef@makeinnocent \dospecials%
\ef@makeinnocent\^^L% and whatever other special cases
\endlinechar\^^M \catcode\^^M=12 \ef@xphoto}%
{\catcode\^^M=12 \endlinechar=-1 %
\gdef\ef@xphoto#1^^M{\def\test{#1}%
\ifx\test\ef@endphototest
\efloat@foundend{ppp}{photo*}
\else\ifx\test\ef@enddblfiguretest
\efloat@foundend{ppp}{photo*}
\else%
\efloat@iwrite{ppp}{#1}%
\let\next\ef@xphoto%
\fi \fi \next}%
}

{\escapechar=-1%
\xdef\ef@endphototest{\string\\end\string\{photo\string\}}%
\xdef\ef@enddblphototest{\string\\end\string\{photo*\string\}}%
}

\@namedef{photo*}{\photo}
\providecommand{\photosection}{Photos}

\newcommand{\processphotos@hook}{\@empty}

\def\processphotos{%
\expandafter\ifnum \csname @ef@pppopen\endcsname>0
\immediate\closeout\efloat@postppp \ef@setct{ppp}{0}
\clearpage
\if@photolist
{\normalsize\listofphotos}
\clearpage
\fi
\section*{\photosection}
\suppressfloats[t]
\fi
\markboth{\uppercase{\photosection}}{\uppercase{\photosection}}%
\processphotos@hook \@input{\jobname.ppp}
\fi}

\renewcommand{\processdelayedfloats}{{%
\def\baselinestretch{1}\normalsize
\let\figure\@bfig
\let\table\@btab
\let\photo\@bphoto
\processdelayedfloats@hook
\if@tablesfirst \processtables\processfigures
\else \processfigures\processtables \fi
\processphotos
\processotherdelayedfloats}}
\makeatother

\begin{document}
\lipsum
\begin{photo}
\centering
\includegraphics{myPhoto}
\caption{My Photo 1}
\end{photo}
\lipsum
\begin{photo}
\centering
\includegraphics{myPhoto}
\caption{My Photo 2}
\end{photo}
\lipsum
\begin{figure}
\centering
\includegraphics{myFigure}
\caption{My Figure}
\end{figure}
\lipsum
\begin{map}
\centering
\includegraphics{myMap}
\caption{My Map}
\end{map}
\lipsum
\end{document}

-
Very nice. I coded some endfloat trickery for the smaller case where one can substitute a figure/table for something else. –  Werner Nov 16 '11 at 4:22
I did not think it was going to be that hard, but once I got into it I kept going... I started looking into providing a means of adding a new float type it, but sure does not seem easy. –  Peter Grill Nov 16 '11 at 4:27
Yes. That's why it seemed to be an author-wish-list candidate. It would be neat to specify all your code using a macro-like approach by issuing something like \newendfloat{<float>}{<ext>}. –  Werner Nov 16 '11 at 4:41
Will adapt my newfloat package to the endfloat package the upcoming week-end... –  Axel Sommerfeldt Nov 16 '11 at 7:55
This is really fantastic. Thank you so much. –  David Nov 16 '11 at 12:21

When using the endfloat package v2.5 one can use \DeclareDelayedFloat to make new floating environments known to the endfloat package:

\documentclass{book}
\usepackage[demo]{graphicx}

\usepackage{float,endfloat}

\newfloat{map}{tbp}{lomap}
\floatname{map}{Map}
\DeclareDelayedFloat{map}{Maps}

\begin{document}

\begin{map}
\centering
\includegraphics{x}
\caption{A map}
\end{map}

\end{document}


Version 2.5 (which offers support for longtables, threeparttables etc. as well) is currently under test by the questioner. If you are interested in testing this version, too, please drop me a e-mail.

Addendum: Version 2.5 is available on CTAN and as TeXlive and MikTeX update right now.

-

If you limit your new floats to two* (say, maps and photos) and you don't have any figures or tables, then you can trick endfloat into thinking that you're working with maps and photos by merely using figure for map and table for photo (plus the appropriate redefinition of certain commands).

First you would define your new floats map and photo using the float package interface. Additionally, you would redefine \listoffigures to be \listof{map}{List of Maps} and \listoftables to be \listof{photo}{List of Photos}. Then, use \begin{figure}[..] ... \end{figure} whenever you want a map, and \begin{table}[..] ... \end{table} whenever you need a photo. You also need to use \captionof{<newfloat>}[..]{...} to obtain a caption for the new float.

Here is a minimal working example illustrating this fact:

\documentclass{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\usepackage[nomarkers]{endfloat}% http://ctan.org/pkg/endfloat
\usepackage{caption}% http://ctan.org/pkg/caption
\usepackage{float}% http://ctan.org/pkg/float
\begin{document}
% ========== MAP FLOAT ==========
\newfloat{map}{htbp}{lom}% \begin{map}[htbp]...\end{map}
\floatname{map}{Map}%
\makeatletter
\renewcommand{\listoffigures}{\listof{map}{List of \fname@map s}}
\makeatother
% ========== PHOTO FLOAT ==========
\newfloat{photo}{htbp}{lop}% \begin{photo}[htbp]...\end{photo}
\floatname{photo}{Photo}%
\makeatletter
\renewcommand{\listoftables}{\listof{photo}{List of \fname@photo s}}
\makeatother

\section{First section}
\lipsum[1]
\begin{figure}[p]
\centering\includegraphics{map1}
\captionof{map}[Beautiful]{This is a beautiful map.}
\end{figure}
\lipsum[2]
\begin{table}[p]
\centering\includegraphics{photo1}
\captionof{photo}[Amazing]{This is an amazing shot.}
\end{table}
\lipsum[3]
\begin{figure}[p]
\centering\includegraphics{map2}
\captionof{map}[Awesome]{This is an awesome map.}
\end{figure}
\lipsum[4]
\begin{table}[p]
\centering\includegraphics{photo2}
\captionof{photo}[Stunning]{This is a stunning picture.}
\end{table}
\lipsum[5]
\end{document}


geometry was used to modify the layout, while lipsum provided dummy text. Additionally, the demo option passed to graphicx was used to replace all images with a 150pt x 100pt black rectangle (for compatibility purposes).

*If this is not the case, then more trickery would be needed. This includes the possibility of using new floats in addition to figure and table` (not just a replacement), or using more than two new floats, or a combination of both.

The last possibility is mentioned on the package author's "wish list", although it has not been implemented, and may likely not be under the current maintainer.

-
Unfortunately, I am using "figures" as well. –  David Nov 16 '11 at 11:20