# tex4ebook: the incorrect order of reference and appendices

I found that the order of reference and appendices is compiled incorrectly by tex4ebook. Sample code:

\documentclass{amsbook}
\usepackage{bookmark}

\begin{document}
\tableofcontents

\chapter{Hello}
Hello

\chapter{Hi}
Hi

\appendix
\chapter{One}

One

\chapter{Two}
Two

\bibliographystyle{amsalphaabrvd}
\bibliography{test}

\end{document}


with test.bbl:

\begin{thebibliography}{DT}

\bibitem[DT]{test}
D.~Trump, \emph{Make America Great Again}, slogan.
\end{thebibliography}


compiled with test.mk4:

if mode == "draft" then
Make:htlatex {}
else
Make:htlatex {}
-- Make:biber {}
Make:htlatex {}
Make:htlatex {}
end

Make:tex4ht{}
Make:t4ht{}


and the configure file:

\Preamble{xhtml,pic-align,new-accents,accent-}
\RequirePackage[T1]{fontenc}
\Configure{Picture}{.svg}
\makeatletter
\makeatother
\DeclareRobustCommand{$}{\begin{equation*}} \DeclareRobustCommand{$}{\end{equation*}}
\begin{document}
\EndPreamble


There are two issues: firstly, reference page is placed before all appendices, and secondly, in the bookmark, the reference is placed as a subsection of the last appendix. I wonder a workaround to fix these.

The handling of appendices was broken in tex4ebook. There are two separate problems. The bibliography comes before appendices because every chapter is put in a separate file, which needs to be registered to the file sequence list. If they are not registered, they are added at the end of file, as it happened with appendices. The second issue is the position of bibliography in the bookmark list. The issue was that the \appendix command was defined as superior to \chapter in the bookmark generator code.
Both of these issues had been fixed in the tex4ebook sources. The fix is too large to be posted here, so you need to update it manually for this moment.