I want to wrap several paragraphs inside a div with a custom class, but the div is closed automatically in the resulting HTML when a new paragraph begins.

This shows the issue:

\Hcode{<div class='FOO'>}

The 'FOO'-div is closed before the 'center'-div is opened.

The tex4ht tutorial begins to explain what I believe is what I need, but ends with "This exercise will be little bit more difficult".

Does anyone know how I can achieve this?

1 Answer 1


The paragraphs must be handled in a specific way in tex4ht. They must be closed before a block element starts. Details are in the linked answer.

I would introduce a custom environment in this case:



another paragraph

It can be then configured in the .cfg file:

{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="foo">}\par}

The \ConfigureEnv command can be used to configure any environment, the \ifvmode\IgnorePar\fi\EndP will handle the paragraph closing before the block element start or end. \par command will ensure a new paragraph opening inside and after the environment.

This is the resulting HTML:

   <div class="foo">
<!--l. 6--><p class="noindent" >test
</p><!--l. 8--><p class="noindent" >another paragraph

  • I had to replace the quotes by single quotes, or else I'd get broken HTML: <div class="foo\global \let \T1\frqq \T1\guillemotright \T1\frqq &lt;!--l. 23--&gt;&lt;p class=" noindent"="">. But I now got it to work the way I wanted. Thanks for the swift response! Very nice work with make4ht, too.
    – Volker
    May 15, 2019 at 12:05
  • @Volker oh really? this shouldn't happen. what was the command you used for the compilation? including options
    – michal.h21
    May 15, 2019 at 12:22
  • make4ht -l -u -f html5 -d html doc.tex "" "" "" "-file-line-error -halt-on-error"
    – Volker
    May 15, 2019 at 12:58
  • Never mind, with the article class it works fine. I was using a custom document class with lots of dependencies. Not sure where the problem is...
    – Volker
    May 15, 2019 at 13:04
  • 1
    @Volker this can be an issue with Babel package, it often redefines characters like parenthesis to produce desired output. it can break things like this.
    – michal.h21
    May 15, 2019 at 13:06

You must log in to answer this question.

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