5

It took me a while to find the cause of this. when giving p{} for table column width, and also using mathml option, then htlatex losses the width specs in the generated HTML table.

It is very simple to reproduce. Below is the .tex files and the commands, and the HTML output.

I need to use mathml since I am using mathjax in htlatex configuration to render the Latex math on the screen. Without using mathml then mathjax does not work. So this is a big problem because now all the tables I have where I specified width of columns are lost in the HTML version.

Minimal working latex file

\documentclass{article}%
\begin{document}
 \begin{tabular}{|p{3in}|p{1in}|p{1in}|}\hline
   blablablaaablabla&blablablaaablabla&blablablaaablabla
   \\\hline
\end{tabular}
\end{document}

This command works

htlatex index.tex "htm,p-width"

enter image description here

This command does not work

htlatex index.tex "htm,mathml,p-width"

enter image description here

The "p-width" option is important. See this for reference on it. it was added by Eitan in 2004 to support column widths in HTML.

Again, I have to use mathml, and I also need to have tables of fixed width columns, or be able to specify the column width. Now I can't do both if I am to use MathJax with htlatx generated HTML.

Any one knows of a work around please?

TL 2012 debian package.

ps. I actually would rather not use Mathjax, but without it, the generated math using .png does not look as good, and I have not figured out how to make it look better. So, may be I should spend more time on this. If I can get htlatex to generated good math using .png images, then I do not have to use Mathjax, and do not have to use the mathml option and the problem will be gone.

0

1 Answer 1

2

Here is a small attempt to make table width appear automatically in HTML file with mathml. I have used the header from MathJax + HTML5 in the configuration file with rest of the macros.

Sample TeX with Tables

\documentclass{article}

\begin{document}

\begin{tabular}{|p{3in}|p{1in}|p{1in}|}\hline
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   $B (x) =-x ^ 2 + 60x-500$
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   &
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   $B (x) =-x ^ 2 $
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   &
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   $B (x) =500$
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   \\\hline
\end{tabular}

\tabwidth{9in}
\begin{tabular}{|p{3in}|p{1in}|p{1in}|l|c|r|}\hline
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   $B (x) =-x ^ 2 + 60x-500$
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   &
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   &
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   blablablaaablabla
   &
   Test
   &
   Test
   & Test
   \\\hline
   a & b & c & a & b & c\\\hline
\end{tabular}

\tabwidth{7in}
\begin{tabular}{lcr lcr lcr}\hline
One & Two & Three & Four & Five & Six & Seven & Eight & Nine \\\hline
\end{tabular}

\end{document}

Configuration File (ht5mathjax-tbwd.cfg)

\Preamble{xhtml,mathml}

\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{<meta http-equiv="Content-Type" 
                               content="text/html; charset=iso-8859-1" />\Hnewline}}
\Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
\Configure{@HEAD}{\HCode{<link
         rel="stylesheet" type="text/css"
         href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
  .MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}
\begin{document}
\EndPreamble

\catcode`\:11
\catcode`\@11

% Added to fix the opening and closing <p> tags
\Configure{HtmlPar}
  {\EndP\HCode{<!--l. \the\inputlineno-->%
<p \csname a:!P\endcsname
         class="no\ifHCond par\else indent\fi" \a:LRdir>}}
  {\EndP\HCode{<!--l. \the\inputlineno-->%
<p \csname a:!P\endcsname
        class="\ifdim \parindent=\z@ no\fi indent" \a:LRdir>}}
  {{\Tg</p>}}
  {{\Tg</p>}}%

{
  \def\x:Em{%
    \catcode`\p=12
    \catcode`\t=12
    \gdef\x:Em}
  \x:Em#1pt{#1}
}
\tmp:dim=10em
\edef\ten:Em#1.#2//{#1}
\edef\ten:Em{\expandafter\ten:Em \the\tmp:dim//}

\newdimen\tmp::dim
\newdimen\tmp:::dim
\def\tabwidth#1{\tmp::dim=#1}
\tmp::dim=5in

\def\paAignType{p}
\let\VBorder\empty   \let\AllColMargins\empty
\newcount\Tab:PCell
\newcount\Tab:PVoid
\newdimen\Tab:Wd
\newdimen\Tab::XWd
\newdimen\Tab:XWd

\Configure{halignTB}{%
   \@ifundefined{abc@Wdth-TBL-\TableNo}
     {}
     {\tmp::dim=\csname abc@Wdth-TBL-\TableNo\endcsname}%
   \Tab::XWd=\tmp::dim%
   \expandafter\ifx\csname abc@WdGZ-TBL-\TableNo\endcsname\relax\else%
       \advance\Tab::XWd by -\csname abc@WdGZ-TBL-\TableNo\endcsname%
       \divide\Tab::XWd by \csname abc@PVoid-TBL-\TableNo\endcsname%
   \fi%
   %
   \divide\tmp::dim by \ten:Em\relax
   \tmp::dim=10\tmp::dim
   \HCode{<table style="table-layout:fixed;width:\expandafter\x:Em \the\tmp::dim em" 
   }}{\HCode{>}\tmp::dim=5in}

\Configure{VBorder}
   {\let\VBorder\empty \let\AllColMargins\empty%
    \global\let\GROUPS\empty \HAssign\NewGroup = 0%
    \Tab:Wd=0pt\HAssign\Tab:PCell = 0\HAssign\Tab:PVoid = 0%
    \gHAdvance\Next:TableNo by 1 \global\let\TableNo=\Next:TableNo }
   {\xdef\VBorder{\VBorder\ifnum \NewGroup> 0 \HCode{\Hnewline</colgroup>}\fi}
    \HAssign\NewGroup = 0  \gdef\GROUPS{rules="groups"}}
   {\Advance:\NewGroup by 1
    \ifnum \NewGroup=1 \xdef\VBorder{\VBorder\HCode{\Hnewline<colgroup
        id="TBL-\TableNo-\ar:cnt g">}}\fi
    \@ifundefined{abc@TBL-\TableNo-\ar:cnt}{}
      {%
        \tmp:dim=\csname abc@TBL-\TableNo-\ar:cnt\endcsname%
        \divide\tmp:dim by \ten:Em\relax
        \tmp:dim=10\tmp:dim
      }%
      \ifx\paAignType\ch:class
        \gHAdvance\Tab:PCell by 1%
        \@ifundefined{abc@TBL-\TableNo-\ar:cnt}{}
          {\advance\Tab:Wd by \csname abc@TBL-\TableNo-\ar:cnt\endcsname}%
      \else
        \gHAdvance\Tab:PVoid by 1%
      \fi
    \xdef\VBorder{\VBorder\HCode{\Hnewline\space<col\Hnewline\space\space id="TBL-\TableNo
       -\ar:cnt"\Hnewline}
       \HColAlign\HCode{\Hnewline}
       \ifx\paAignType\ch:class
         \HCode{ width="\expandafter\x:Em \the\tmp:dim em"\Hnewline}
         \immediate\write\@auxout{\string\expandafter\string\gdef%
            \string\csname\space abc@TBL-\TableNo-\ar:cnt\string%
            \endcsname{\csname @testpach \ar:cnt\endcsname}}
       \else
         \@ifundefined{abc@WdLCR-TBL-\TableNo}
           {\HCode{ width="1*"\Hnewline}}
           {\HCode{ width="\csname abc@WdLCR-TBL-\TableNo\endcsname"\Hnewline}}%
       \fi
       \HCode{/>}}\xdef\AllColMargins{\AllColMargins1}}
   {\xdef\AllColMargins{\AllColMargins 0}}
\Configure{halignTD} {}{}
   {<}{\HCode{ style="white-space:nowrap; text-align:left;"}}
   {-}{\HCode{ style="white-space:nowrap; text-align:center;"}}
   {>}{\HCode{ style="white-space:nowrap; text-align:right;"}}
   {^}{\HCode{ style="vertical-align:top; white-space:nowrap;"}}
   {=}{\HCode{ style="vertical-align:baseline; white-space:nowrap;"}}
   {|}{\HCode{ style="vertical-align:middle; white-space:nowrap;"}}
   {_}{\HCode{ style="vertical-align:bottom; white-space:nowrap;"}}
   {p}{\HCode{ style="white-space:wrap; text-align:left;"}}%
   {m}{\HCode{ style="white-space:nowrap; text-align:left; vertical-align:middle;"}}
   {b}{\HCode{ style="white-space:nowrap; text-align:left; vertical-align:baseline;"}}
   {}

\def\putVBorder{\expandafter\put:VBorder\VBorder</>!*?: }
\def\put:VBorder#1</#2>#3!*?: {\def\:temp{#2}\ifx\:temp\empty
     \VBorder%
     \def\:temp{#1}\ifx\:temp\empty \else\ifnum \NewGroup> 0\HCode{\Hnewline</colgroup>}\fi\fi
  \else  \def\:temp{\put:VBorder#3!*?: }\expandafter\:temp\fi
  \immediate\write\@auxout{\string\expandafter\string\gdef%
     \string\csname\space abc@TBL-\TableNo\string%
     \endcsname{\ar:cnt}}
  \immediate\write\@auxout{\string\expandafter\string\gdef%
     \string\csname\space abc@PCell-TBL-\TableNo\string%
     \endcsname{\Tab:PCell}}
  \immediate\write\@auxout{\string\expandafter\string\gdef%
     \string\csname\space abc@PVoid-TBL-\TableNo\string%
     \endcsname{\Tab:PVoid}}
  \expandafter\ifx\csname abc@PCell-TBL-\TableNo\endcsname\relax%
  \else%
     \expandafter\ifnum\csname abc@PVoid-TBL-\TableNo\endcsname=0%
        \immediate\write\@auxout{\string\expandafter\string\gdef%
           \string\csname\space abc@Wdth-TBL-\TableNo\string%
           \endcsname{\the\Tab:Wd}}
     \fi%
     \expandafter\ifnum\csname abc@PVoid-TBL-\TableNo\endcsname>0%
        \immediate\write\@auxout{\string\expandafter\string\gdef%
           \string\csname\space abc@WdGZ-TBL-\TableNo\string%
           \endcsname{\the\Tab:Wd}}
        \divide\Tab::XWd by \ten:Em\relax
        \Tab::XWd=10\Tab::XWd
        \immediate\write\@auxout{\string\expandafter\string\gdef%
           \string\csname\space abc@WdLCR-TBL-\TableNo\string%
           \endcsname{\expandafter\x:Em \the\Tab::XWd em}}%
     \fi%
  \fi%
}

\endinput

Command Line

htlatex <filename> ht5mathjax-tbwd

Know Problem

  1. The cfg writes to .aux for calculating the width of the cell. So you need to run at least twice the htlatex command.
  2. If a table contains only cells with p{...} value (for example in the first tabular of my example), then no need to provide \tabwidth{...} before \begin{tabular}{...}. The configuration file itself will calculate the width by adding the cell widths. If any of the cell contains l,c,r, the you need to set \tabwidth{...}, otherwise the cells will overlap when we view in browser.

Hope this helps.

1
  • @Nasser: You can also switch to dvipng from convert via tex4ht.env , which creates better quality images. For this please see the answer to this post.
    – Jagath
    Commented Jul 29, 2013 at 17:10

You must log in to answer this question.

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