3

Here is my MWE:

\documentclass[]{book}
  \input{tex4ht.sty}
  \Preamble{xhtml}
  \Configure{subsection}{\HCode{<i>}}
    {\HCode{</i>}}
    {\HCode{<b>}}
    {\HCode{</b>}}
\begin{document}
  \EndPreamble
\subsection{One}
This is one
\subsection{Two}
This is two
\end{document}

In other words, the whole subsection should be wrapped in <i> tags and the heading in <b> tags.

Compiling with ht latex test.tex yields this between the <body> tags:

<!--l. 10--><p class="indent" >   <i><b><a 
 id="x1-10000.0.1"></a>One</b> This is one
</p>
<!--l. 12--><p class="indent" >   </i><i><b><a 
 id="x1-20000.0.2"></a>Two</b> This is two </i></p> 

Note that after <!--l. 12-->, the <p class="indent" > starts a new subsection before the previous subsection is closed with the </i> tag. In my actual example, this is a </idx:entry> tag and the improper nesting throws an error.

Perhaps there is an explicit way to end the subsection that would flush the </i> tag before starting the <p> for the new subsection?

Thanks for any help!

2

You can deal with <p> using some tex4ht internal commands. In this case, you need to:

  1. close all paragraphs before section start at <i>
  2. suppress <p> inside header
  3. start new noindent paragraph after header
  4. close paragraph before section end with </i>

So you can use this configuration:

  \Preamble{xhtml}
  \Configure{subsection}{\EndP\IgnorePar\HCode{<i>}}
    {\EndP\IgnorePar\HCode{</i>}}
    {\HCode{<b>}}
    {\HCode{</b>}\par\IgnoreIndent\ShowPar}
\begin{document}
  \EndPreamble

\EndP close all <p> elements, \IgnorePar will suppress inserting paragraphs inside the header, after header end, we need to explicitly end paragraph with \par, \IgnoreIndent request next paragraph to be with no indent and \ShowPar will show starting <p> tag:

 <i><b><a 
 id="x1-10000.0.1"></a>One</b>
<!--l. 4--><p class="noindent" >This is one
</p>
   </i><i><b><a 
 id="x1-20000.0.2"></a>Two</b>
<!--l. 6--><p class="noindent" >This is two
</p><!--l. 8--><p class="indent" >   Hello world
</p><!--l. 10--><p class="indent" >  another paragraph
</p>
   </i><i><b><a 
 id="x1-30000.0.3"></a>Three</b>
<!--l. 13--><p class="noindent" >This is three
</p><!--l. 15--><p class="indent" >  Hello, hello
</p>
   </i>
  • Thank you, @michal.h21. After posting this, I managed to figure part of it out, but this helps to clarify it. I now understand that \EndP closes the previous paragraph, but the fact that you put the \par in after the header (presumably to close the previous paragraph), is not at all intuitive! Thanks, as always. – Nat Kuhn Oct 19 '14 at 13:36
  • @NatKuhn I put \par to start a new paragraph, because it is not started automatically when there is no blank line between subsection and following text – michal.h21 Oct 19 '14 at 13:42
  • @michal.h21 Is there a documentation about tex4ht internal commands? I found casual explanation for Tg and HCode, here you explain that \par means "start a new paragraph if not already started", but many other commands remain unclear. – mmj Aug 12 '16 at 9:03
  • @mmj \par is internal TeX command, it isn't provided by tex4ht. There is documentation for basic configurations, see especially tex4ht and LaTeX chapters. Basic documentation for commands is here, you can see sample usage when you click on numbered links before the commands. – michal.h21 Aug 12 '16 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.