2

I found a problem using tex4ht with SVG for math.

I needed to make a table and put math in it. I found that the same math inside the table looks bad compared to the math outside the table. After some debugging, it turned out that tex4ht needs the following configuration to fix the math inside the table

\ifdefined\HCode
\Configure{$}{\PicMath}{\EndPicMath}{}
\Configure{PicMath}{}{}{}{class="math";align="absmiddle"}
\fi

I have no idea why that is. Here is a MWE showing the difference in math inside the table vs. outside when the above tex4ht configuration is missing:

\documentclass[11pt]{article}
\usepackage{amsmath,mathtools,amssymb}   

\begin{document} 

%\ifdefined\HCode
%\Configure{$}{\PicMath}{\EndPicMath}{}
%\Configure{PicMath}{}{}{}{class="math";align="absmiddle"}
%\fi

\begin{align*}
\left( x+y \left( x \right)  \right) {\frac {d}{{d}x}}y \left( x \right) &=x-y \left( x \right)\\
    {t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {d}{{d}t}}y \left( t \right) &=0\\
    t-2\,{{e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{ e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {d}{{\rm d}t}}y \left( t \right) &=0
\end{align*}

\begin{center}
\begin{tabular}{|c|c|}\hline    
1&$ \left( x+y \left( x \right)  \right) {\frac {\rm d}{{\rm d}x}}y \left( x \right) =x-y \left( x \right) $\\\hline 
2&$3\,{t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline 
3&$2\,t-2\,{{\rm e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{\rm e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{\rm e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline
\end{tabular}
\end{center}

\end{document}

Then compiled with

rm -f *.svg
make4ht -ul -f html5+dvisvgm_hashes foo.tex "htm,pic-align,p-width,svg"
make4ht -ul -f html5+dvisvgm_hashes foo.tex "htm,pic-align,p-width,svg"

Mathematica graphics

Clearly the math inside the table cells is not correct. Lots of misalignments over the baseline and the spacing between some of the letters is cramped in a number of places. Below is the result of the same code above, but when removing the comments on the \ifdefined code, so it is now active:

Mathematica graphics

Now the math is correct inside the table. It looks just like the math outside.

Well, you might ask, then why not then keep the \ifdefined code in there and the problem is solved, right?

But here comes the actual problem.

Keeping the \ifdefined code in there to fix the math, causes a big problem somewhere else.

Now tex4ht will no longer accept fixed width column for tables p-width. And I need to have fixed width columns since the actual table will get too wide (it has other columns, not shown here). Making it hard to see the table on the web page without having to scroll all the time.

So now when I want to make a table, and for example have the cells be say 2 inch wide, it will not work.

\documentclass[11pt]{article}
\usepackage{amsmath,mathtools,amssymb}   

\begin{document} 
\ifdefined\HCode
\Configure{$}{\PicMath}{\EndPicMath}{}
\Configure{PicMath}{}{}{}{class="math";align="absmiddle"}
\fi

\begin{center}
\begin{tabular}{|p{1in}|p{2in}|}\hline    
1&$ \left( x+y \left( x \right)  \right) {\frac {\rm d}{{\rm d}x}}y \left( x \right) =x-y \left( x \right) $\\\hline 
2&$3\,{t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline 
3&$2\,t-2\,{{\rm e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{\rm e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{\rm e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline
\end{tabular}
\end{center}

\end{document}

Now

rm -f *.svg
make4ht -ul -f html5+dvisvgm_hashes foo.tex "htm,pic-align,p-width,svg"

Mathematica graphics

tex4ht just ignored p-width. To get the width to work, I had to remove the \ifdefined code, like this:

\documentclass[11pt]{article}
\usepackage{amsmath,mathtools,amssymb}   

\begin{document} 

\begin{center}
\begin{tabular}{|p{1in}|p{2in}|}\hline    
1&$ \left( x+y \left( x \right)  \right) {\frac {\rm d}{{\rm d}x}}y \left( x \right) =x-y \left( x \right) $\\\hline 
2&$3\,{t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline 
3&$2\,t-2\,{{\rm e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{\rm e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{\rm e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline
\end{tabular}
\end{center}

\end{document}

Mathematica graphics

Now p-width works. But the math became bad again. So back to square one.

I need to be able to have table with fixed width columns, and also have the math look as nice as math outside the table, and still use SVG. But there is a conflict.

For some reason, make4ht math is not rendered correctly inside table cells when using SVG and also using \Configure{$}{\PicMath}{\EndPicMath}{} at same time. May be it is dvisvgm issue. I do not know.

Is there a way around this?

I am using latest TL 2018, with most recent updates for make4ht and tex4ht.

10
  • try the pic-tabular option. It will make picture for the whole table
    – michal.h21
    Commented Aug 29, 2018 at 10:28
  • @michal.h21 thanks for the suggestion. It did not work for me. I tried make4ht -ul -f html5+dvisvgm_hashes foo.tex "htm,pic-align,p-width,pic-tabular,svg" but the it did not have any effect. Table is not an image. Did it work for you? Math inside table cells still looked bad. But even it can be made to work, this is not practical solution for long term. As the table has lots of text as well as math. If the whole table is an image, it means one can't copy any text using the mouse from the webpage where the table is showing, as it is one big image. As a workaround, might be OK though.
    – Nasser
    Commented Aug 29, 2018 at 11:00
  • another option is to use pic-m to make all inline math picture
    – michal.h21
    Commented Aug 29, 2018 at 11:15
  • the make4ht -ulm draft -f html5+dvisvgm_hashes sample.tex "htm,pic-m,pic-align,svg,p-width" works for me, without any custom configurations.
    – michal.h21
    Commented Aug 29, 2018 at 11:53
  • @michal.h21 tried the above command. It does not work I am afraid. The table width is ignored. The math is fine, but that is the whole point of the question. I want the table column width be fixed, and also the math to stay good as outside the table. I tried your command with \ifdefined\HCode in there, and without it. The table column width did not change as it should. Did the width of the column when you tried it? Thanks.
    – Nasser
    Commented Aug 29, 2018 at 12:24

1 Answer 1

2

The pic-tabular option requires conversion of all tabular environments to pictures. If you want to convert only some of these tables, it is best to use a custom environment which will convert the enclosed code to pictures.

It can look like this:

% file pictureenv.sty
\newenvironment{pictureenv}{}{}
\endinput

It needs the tex4ht configuration:

% pictureenv.4ht
 \ConfigureEnv{pictureenv}{\Picture*{}}{\EndPicture}{}{}

And usage sample:

\documentclass[11pt]{article}
\usepackage{amsmath,mathtools,amssymb}   

\usepackage{pictureenv}
\begin{document} 


\begin{align*}
\left( x+y \left( x \right)  \right) {\frac {d}{{d}x}}y \left( x \right) &=x-y \left( x \right)\\
    {t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {d}{{d}t}}y \left( t \right) &=0\\
    t-2\,{{e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{ e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {d}{{\rm d}t}}y \left( t \right) &=0
\end{align*}

\begin{center}
  \begin{pictureenv}
    \begin{tabular}{|p{1in}|p{2in}|}\hline    
    1&$ \left( x+y \left( x \right)  \right) {\frac {\rm d}{{\rm d}x}}y \left( x \right) =x-y \left( x \right) $\\\hline 
    2&$3\,{t}^{2}+4\,ty \left( t \right) + \left( 2\,{t}^{2}+2\,y \left( t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline 
    3&$2\,t-2\,{{\rm e}^{ty \left( t \right) }}\sin \left( 2\,t \right) +{{\rm e}^{ty \left( t \right) }}\cos \left( 2\,t \right) y \left( t \right) + \left( -3+{{\rm e}^{ty \left( t \right) }}t\cos \left( 2\,t \right)  \right) {\frac {\rm d}{{\rm d}t}}y \left( t \right) =0$\\\hline
  \end{tabular}
  \end{pictureenv}
\end{center}

\end{document}

enter image description here

3
  • hi Micahl. I found small bug. It is when I used listing package. Should I post separate question on this (might be easier) or should I post the new problem here? the new environment you defined replaces some characters in the listings with an "x" for some reason. i.e when I added a second field to the table, and put lstlisting in that cell, some characters are changed. This only shows when using the new environment.
    – Nasser
    Commented Aug 30, 2018 at 18:38
  • For example: \ifdefined\HCode \begin{pictureenv} \fi \begin{tabular}{|p{3in}|p{2.5in}|}\hline ${\frac {d}{{d}x}}y \left( x \right) = \left( -2+x \right) ^{2}$& \begin{lstlisting} [_quadrature_] \end{lstlisting}\\\hline \end{tabular} \ifdefined\HCode \end{pictureenv} \fi and compile that with same command we were using, you'll see the problem. Need to add \usepackage{listings} This is what I get !Mathematica graphics notice the x letters added to the listing. It does not seem to like [ and _ in the listings
    – Nasser
    Commented Aug 30, 2018 at 18:45
  • @Nasser this is a different issue, can you post a new question?
    – michal.h21
    Commented Aug 30, 2018 at 18:58

You must log in to answer this question.

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