# Control the <p> tags added by Tex4HT

TeX4HT allows to reset LaTeX macros to insert HTML code in order to produce clean HTML documents. This is great, but it often gets in a mess of <p> tags, such as:

<p class="noindent" ><hr />Some text</p>


after I set a command to insert <hr />. Here I'd like <hr /> to be outside any <p> tag.

There's worse. Sometimes it just generates code which is plain wrong, like:

<p class="noindent"><span class="small-caps"></p><p class="noindent">Some text</p></span>


after I set a command to set small caps.

Is there a way to control these <p> tags to make them behave properly?

-
Do you use custom commands and configurations or just standard LaTeX? Can you post mwe? –  michal.h21 Aug 7 '12 at 7:02
It's not standard, there's quite a few personal commands. The code is on github.com/cc-translators/sagesse. It is built by typing make sagesse_lulu.html. –  ℝaphink Aug 7 '12 at 7:37

Paragraph handling is little bit tricky with tex4ht. Some information can be found in the article TeX4ht configure: Part 1.

There are two issues, if command with configuration hooks is at the beginning of the paragraph.

If some hook is inserted at the beginning of the paragraph, it must place the

tag manually, with some of commands described in the article. The code usually looks like:

\Configure{chapHook}{%
\ifvmode \IgnorePar\fi \EndP\Tg<h2 class="dvmonth">}{\Tg</h2>\IgnoreIndent}


This will include block level element with no paragraphs inside, \IgnoreIndent will cause next paragraph to have class="noindent".

For inline elements, it can look:

\Configure{sample}{\ifvmode \ShowPar\fi \HCode{<i>}}{\Tg</i>}


There is probably bug with \Tg<> command, which causes that its content gets before

tag. Solution is to use \HCode instead in the hooks which are inserted at beginning of the paragraphs.

%Wrong, gives: <i><p>
\Configure{sample}{\ifvmode \ShowPar\fi \Tg<i>}{\Tg</i>}
%Good:
\Configure{sample}{\ifvmode \ShowPar\fi \HCode{<i>}}{\Tg</i>}


Edit: As Ulrike Fisher pointed out in comments, there are some details about configuring.

If you have some custom commands and you want to provide configurations for them, it is best to collect them in some package like mycommands.sty. Then you can provide file mycommands.4ht, which is called automatically by tex4ht when you include mycommands.sty.

For every configuration, you need to provide three things:

1. Create configuration hooks. This is done with

\NewConfigure{sample}{2}

This will create configuration hooks \a:sample and \b:sample.

2. Redefine command to include configuration hooks:

\renewcommand\sample[1]{\a:sample#1\b:sample}

3. Provide default configuration for hooks

\Configure{sample}{\Tg<tag name>}{\tg</tag name>}

This configuration will be then used as default.

You can redefine default configuration in custom config file, which is specified at command line when running tex4ht.

mysample.cfg:

\Preamble{xhtml, charset=utf-8}
\Configure{sample}{\Tg<another tag>}{\Tg</another tag>}
\begin{document}
\EndPreamble


To be compiled with

htlatex myfile "mysample, other options" " -cunihtf -utf8"


Last possibility to put configuration somewhere in your tex file in block that is called only when running with tex4ht

...

note that there are some commands disabled, like \Css and this method is best be used for testing purposes only