This question is an extension of force floats to end of pdf, but keep numbering per chapter (two versions of document pdf).
Like the original post, I would like to have a version of my document with all the figures at the end. The figures should be numbered just as they would be if they were in the normal text of the document (Fig 1.1, Fig 1.2 would be the first two figures in chapter 1).
The solution from the linked post works great until I add an appendix. The appendix command makes the chapters start from A, so the figures end up with titles like A.1 and A.2 for the first two figures in chapter 1 (and B.1 for the first in chapter 2). I've tried adding
\setcounter{chapter}{0}
after the appendix, but that does not help.
The code seems very close to what I would like to do. Is there some simple addition to make it work with an appendix? Thanks!
Here is a MWE:
\usepackage{etoolbox}
\usepackage{appendix}
\usepackage[nomarkers]{endfloat}
\makeatletter
@ifpackageloaded{endfloat}
{
\efloat@condopen{fff}
\pretocmd@chapter{\immediate\write\efloat@postfff{\noexpand\stepcounter{chapter}}}{}{\fail}
\AtBeginFigures{\setcounter{chapter}{0}}
}{}
\makeatother
\usepackage{hyperref}
\begin{document}
\chapter{A}
\begin{figure}
\caption{a figure in chapter 1}\label{fig:1}
\end{figure}
\begin{figure}
\caption{a second figure in chapter 1}
\end{figure}
see \ref{fig:1} and \ref{fig:2}
\chapter{B}
\begin{figure}
\caption{a figure in chapter 2}
\end{figure}
\begin{figure}
\caption{a second figure in chapter 2}\label{fig:2}
\end{figure}
\appendix
\chapter{Appendix A}
this is the appendix
\setcounter{chapter}{0} % <-- no difference
% \renewcommand{\thechapter}{\numeric{\the\value{\chapter}}} % <-- this causes an error but maybe on the right track?
\end{document}