# How can I add custom HTML code to the beginning and end of the body element with tex4ht?

I need to convert a Latex document to several HTML files. I'm using tex4ht for this. What I need next is to add some features to the web pages. I managed to add the needed extra elements in the head section by writing a .cfg file and adding lines like the following one.

\Configure{@HEAD}{\HCode{<meta charset="utf-8" />\Hnewline}}


Now I need to add the HTML code right after <body> and before </body> to wrap the content generated by tex4ht in some divs that the extra functionality to the web pages. How can I do that? Where can I find good documentation about tex4ht usage? Thanks!

You have two options for configuring <body> element, first one is Configure{BODY}{start}{end}, the second is \Configure{@BODY} and \Configure{@/BODY}. In your case it is better to use the second option, which is similar to \Configure{@HEAD}, because you can use it several times to add stuff after and before <body>.:

\Preamble{xhtml}

\Configure{@BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{<article class="main">}}
\Configure{@/BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{</article>}}
\begin{document}

\EndPreamble


this configuration produces:

</head><body
>
<article class="main">
...
document body
...
</article>
</body></html>


regarding documentation, besides documentation linked from tex4ht website, you can also browse literate sources of tex4ht, which are huge, most important are tex4ht-info, which contains some coments on particular configurations and tex4ht-html4 with configurations used in conversion to HTML

• Thanks! This worked for me! I'll see the links you gave here. Thanks again! – Matteo Ipri Mar 3 '16 at 16:00