Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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

1 Answer 1

up vote 6 down vote accepted

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

...
\@ifpackageloaded{tex4ht}{
\Configure{sample}{\HCode{<bla bla>}}{\HCode{</bbla bla>}
}{}
...

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

share|improve this answer
    
Great, thank you! –  ℝaphink Aug 7 '12 at 10:54
    
Now my documents are valid XHTML 1.0 documents! –  ℝaphink Aug 7 '12 at 11:22
    
This is great! :) –  michal.h21 Aug 7 '12 at 11:39
    
Someone should write a book about TeX4HT, it's a great tool once you know how to use it! –  ℝaphink Aug 7 '12 at 11:50
    
Maybe we could start with community wiki here, I would add some details about creating configurations etc., but my knowledge in other areas like font handling is really limited. –  michal.h21 Aug 7 '12 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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