[tex4ht] [bug #477] Support for new LaTeX hook management

Michal Hoftich michal.h21 at gmail.com
Tue Apr 18 18:01:14 CEST 2023

> This won't fix the error with \DocumentMetadata as the
> testphase code loads there amsmath not with the standard hooks but in
> our own hook:
> \tl_gput_right:Nn \@kernel at before@begindocument
>   { \RequirePackage { amsmath } }
> (which doesn't look right, but moving it to
> \@kernel at after@begindocument at before doesn't work either).
> We could probably load amsmath earlier, but naturally the problem
> could reappear with other packages or code.

when I tried to call this command together with the other two hooks in
tex4ht.sty, it produced a fatal error. Amsmath was loaded, but there
were other errors related to the tagging code.

I will need to investigate it more, but the only thing that I found to
work so far is to require tex4ht.sty right at the beginning of the
processing, and to redefine \DocumentMetadata to do nothing.

> 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:

\ifx \config:file\empty
   \def\:temp{\ifx \config:opt\:UnDef
   \edef\config:opt{\ifx \config:file\empty html\fi}\fi
   }\csname begin\endcsname{document}\EndPreamble
   \def\:temp{\input \config:file\relax
\fi \:temp

It checks if the .cfg file was required, if it wasn't, it will call
\Preamble, \begin{document}, and \EndPreamble. The config file needs
to call these commands too, but it can also contain \Configure
commands used before \begin{document}, so it depends on the fact that
.4ht files should be loaded at that moment. I've also tried to call
original \begin{document} before this code block, but it produced more
errors. So again, something to investigate more.

Best regards,

More information about the tex4ht mailing list.