[tex4ht] How do I remove the <hr> tag surrounding floats?

Michal Hoftich michal.h21 at gmail.com
Wed Jul 2 12:47:16 CEST 2014


Hi,

this question was asked also on TeX.sx [1], I will post my answer here as well:

----------------------------
You've identified code for float configuration correctly. It doesn't
work in the config file because of \:xhtml command. Macros with : in
name work only in .4ht files, because they have different \catcode
here. If you want to use it outside 4ht files, you need to set
\catcode of : character to category 11, so it can be used in command
names.

\Preamble{html}
\def\makecolonletter{%
  \edef\makecolonother{\catcode\string`\string : \the\catcode\string`\:\relax}
  \catcode`\:=11\relax%
}
\def\makecolonother{}

\makecolonletter
\Configure{float}
   {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
   {\:xhtml{\IgnorePar\EndP}\HCode{<div
     class="float"\Hnewline>}}
   {\ifvmode \IgnorePar \fi\EndP
    \HCode{</div>}\csname par\endcsname\ShowPar}
\makecolonother
\begin{document}
\Css { .quotation { margin-bottom:0.25em; margin-top:0.25em;
margin-left:4em; margin-right:4em } }
\EndPreamble

I've defined commands \makecolonletter and \makecolonother which take
care of setting catcodes. Now you can use \makecolonletter before
\Configure commands where commands with colon in name are used, don't
forget to use \makecolonother to restore \catcode of colon back.

It seems that \:xhtml expands it's argument only when xhtml mode is
on, otherwise, argument is discarded.

As you want to produce epub, you should definitely use xhtml mode,
because it is the format epub is based on.
----------------------

Best regards,
Michal



[1] http://tex.stackexchange.com/q/187246/2891
[2] http://tex.stackexchange.com/a/187511/2891

2014-07-01 22:10 GMT+02:00 David Strip <tex4ht at stripfamily.net>:
> In book style (and no doubt many others), tex4ht generates an <hr> before
> and after floats. While I don't pretend to understand the mechanics, it
> looks like it is created by this snippet from the html4.4ht file:
>
> \Configure{float}
>    {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
>    {\:xhtml{\IgnorePar\EndP}\HCode{<hr class="float"\xml:empty><div
>      class="float"\Hnewline>}}
>    {\ifvmode \IgnorePar \fi\EndP
>     \HCode{</div><hr
>         class="endfloat" />}\csname par\endcsname\ShowPar}
>
>
> I tried adding the above code, minus the <hr ..> tags to my cfg, but then my
> latex file fails to run through tex4ht. I get a "Missing $ inserted" error
> when a \begin{center} is encountered after \begin{table}. Here's a simple
> example:
>
> \documentclass{book}
> \begin{document}
> \chapter{Simple Example}
> \begin{table}
> \begin{center}
> \hbox{
> \begin{tabular}{|l|c|c|}\hline
> entry1&entry2&entry3\\
> entry4&entry5&entry6\\ \hline
> \end{tabular}}
> \end{center}
> \caption{a caption}
> \end{table}
> \end{document}
>
> I then tried just placing an unmodified copy of the \Configure{float} ... in
> my .cfg file and still get the error, so I guess I'm not supposed to put
> that chunk of code into my .cfg
>
> So, how do I achieve my goal?
> Thanks.



More information about the tex4ht mailing list