4

It appears that the content inserted via \AtBeginDocument is being ignored by htlatex. Is there a workaround to this other than not using \AtBeginDocument?

To reproduce save the MWEs below and run

htlatex <filename>

The only difference between the two is that one uses \AtBeginDocument{\Dedication} and the other has \Dedication in the main body of the document.

Using \Dedication in the main body produces

<!--l. 9--><p class="indent" >   This is dedicated to me as I wrote it!! :-)

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html> 

whereas using \AtBeginDocument{\Dedication} produces

<!--l. 11--><p class="indent" >

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html> 

Note that the dedication text is missing.

References


Code: Dedication

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\begin{document}
\Dedication
\chapter{First Chapter}
Text for first chapter.
\end{document}

Code: \AtBeginDocument{\Dedication}

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\AtBeginDocument{\Dedication}%

\begin{document}
\chapter{First Chapter}
Text for first chapter.
\end{document}

1 Answer 1

3

The problem is that lot of things is happening at begin document in tex4ht. This is the moment when patches from .4ht files are loaded, and html header is printed. So your dedication text is printed before any html tags in your example. Probably easiest solution is to use etoolbox command \AfterEndPreamble, which print content after all \AtBeginDocument commands are done:

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\usepackage{etoolbox}
%\AtBeginDocument{\Dedication}%
\AfterEndPreamble{\Dedication}
\begin{document}
\chapter{First Chapter}
Text for first chapter.
\end{document}

and the result:

<!--l. 11--><p class="indent" >   This is dedicated to me as I wrote it!! :-)

</p>
   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .