>> Well I know that rewriting such patches is hard, but this \document
>> redefinition looks very fragile. Sadly I can't make a concrete suggestion
>> how to change it as I have no idea what all the code is doing and what
>> should come before and after other things.
> Yes, it will be fragile, unfortunately. This is the code that loads
> .4ht files and then calls the original \document:
[...]
> It checks if the .cfg file was required, if it wasn't, it will call
> \Preamble, \begin{document}, and \EndPreamble.
[...]
I know, I mean I checked the code and see the details. What I do not
understand is the overall picture.
So if you do a step back and remove in your mind all this
redefinitions and assume a fresh, unchanged \document command.
Which tasks do you have to do when you encounter \begin{document} and
which when you encounter \document?
Which of them can you do with the normal hooks?
Which of them can't you do and why not? What fails?
Ulrike