# [tex4ht] [bug #435] tex4ht: Creates invalid html document when using \AtBeginDocument

Michal Hoftich michal.h21 at gmail.com
Wed Aug 14 10:06:40 CEST 2019

Follow-up Comment #1, bug #435 (project tex4ht):

The \AtBeginDocument command is usually used to redefine macros and
initialize stuff. This use works. What is the issue in this case is that it
includes a text in the document. As tex4ht outputs the HTML header at this
moment as well, it happens that the text goes  before HTML.

I don't think we can fix that easily, as we want the code usually executed in
\AtBeginDocument to be executed before any output is written. In this
particular case, I would advice to edit the document:

-----------
\documentclass[english]{minimal}
\usepackage[utf8]{inputenc}

\newcommand\outputatbegin[1]{#1}

\makeatletter
\AtBeginDocument{\outputatbegin{\@title}}
\makeatother
\title{Minimal example}
\begin{document}
Test body.
\end{document}
------------

The \outputbegin command can then be redefined for tex4ht in a custom config
file:

-------------
\Preamble{xhtml}
\renewcommand\outputatbegin[1]{\Configure{@BODY}{#1}}
\begin{document}
\EndPreamble
-------------

The redefinition uses the \Configure{@BODY} command that will output the
text after the <body> tag.

_______________________________________________________