1

I am making a table, with one column. The table is centered. The column type is centered paragraph.

I am using \downarrow for annotation between each row to indicate transformation made.

In pdf, everything is centered. But in HTML, the math is centered, but the arrows are not. This happens only when I use column type as centered paragraph. If I use just c, then the arrows are centered.

But I have to use centered paragraph and not c for column type, because I am using displayed math in table, which needs paragraph. I am using displayed math because the math is little larger and easier to read.

Here is an example that works same way in PDF and HTML, which using c. Then below that I show an example which does not work in HTML when I change the column type to centered paragraph

\documentclass[12pt,oneside]{book}

%added nov 23, 2023 to enlarge vertical arrow. %https://tex.stackexchange.com/questions/213811/how-to-elongate-down-arrow \newcommand{\xdownarrow}[1]{% {\left\downarrow\vbox to #1{}\right.\kern-\nulldelimiterspace} } \usepackage{amsmath}

\begin{document}

\begin{table} \centering \begin{tabular}{c} $\int \frac{e^{x+e^x} \left(e^x+1\right)}{x+e^x} , dx$\ $\Big\downarrow$ \rlap{7258}\ $\int \frac{e^{x+e^x}}{x+e^x}d\left(x+e^x\right)$\ $\Big\downarrow$ \rlap{2609}\ $\operatorname{ExpIntegralEi}\left(x+e^x\right)$ \end{tabular} \end{table}

\end{document}

Compiling with lualatex gives

enter image description here

Compiling with tex4ht using

make4ht -ulm default -a debug foo.tex "mathjax,htm,nostyle"

Gives

enter image description here

Output is similar. arrows are centered

Now I modified the MWE to using column type centered paragraph so I can use display math

\documentclass[12pt,oneside]{book}  
%added nov 23, 2023 to enlarge vertical arrow.
%https://tex.stackexchange.com/questions/213811/how-to-elongate-down-arrow
\newcommand{\xdownarrow}[1]{%
  {\left\downarrow\vbox to #1{}\right.\kern-\nulldelimiterspace}
}

\usepackage{array} %see https://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef \newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}

\usepackage{amsmath}
\begin{document} \begin{table} \centering \begin{tabular}{C{\textwidth}} $\displaystyle \int \frac{e^{x+e^x} \left(e^x+1\right)}{x+e^x} , dx$\ $\Big\downarrow$ \rlap{7258}\ $\displaystyle \int \frac{e^{x+e^x}}{x+e^x}d\left(x+e^x\right)$\ $\Big\downarrow$ \rlap{2609}\ $\displaystyle \operatorname{ExpIntegralEi}\left(x+e^x\right)$ \end{tabular} \end{table}

\end{document}

Now lualatex gives

enter image description here

But tex4ht gives using same command as above this:

enter image description here

The arrows for some reason no longer centered as in PDF.

Is there an easy workaround for this?

TL 2023 updated about 2 months ago.

Tex4ht tracking number

Nasser
  • 20,220
  • Did you try the tikz-cd package? But I don't know how well the output can be converted with tex4ht. – Jasper Habicht Nov 22 '23 at 08:46
  • @JasperHabicht I did not. That is way much more complicated for me than just using table and downarrow. I am not very good with tikz, also since I have to compile everything to HMTL also, I try to avoid using tikz unless necessary. tex4ht supports tikz graphics, but there can be some issues. – Nasser Nov 22 '23 at 08:48
  • 1
    The problem is that there is a number right to the arrow which makes it shift to the left (so that everything in this cell is centered, not only the arrow). To avoid this, you can place the number in a zero-sized box, e.g. with \rlap{7258}. Since \rlap is a quite basic command (but not for use in math mode), I would guess that the conversion works well. But I did not test it. – Jasper Habicht Nov 22 '23 at 08:50
  • @JasperHabicht Ok, thanks. Will use your suggestion and update the MWE – Nasser Nov 22 '23 at 08:52

1 Answers1

1

Try this configuration file:

\Preamble{xhtml}

\catcode\:=11 \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:normal; text-align:left;"}\Protect\a:HColWidth} {m}{\HCode{ style="white-space:normal; text-align:center; vertical-align:middle;"}\Protect\a:HColWidth} {b}{\HCode{ style="white-space:normal; text-align:left; vertical-align:bottom;"}\Protect\a:HColWidth} {} \catcode:=12 \begin{document} \EndPreamble

It is a configuration for possible values of table column specifications. In theory, it should be possible to add line for your C specification here, but it seems that it is converted to m specification by array internally. So I've changed the configuration for m to align to center: {m}{\HCode{ style="white-space:normal; text-align:center; vertical-align:middle;"}\Protect\a:HColWidth}. I won't change it in TeX4ht sources, because m columns should be normally left aligned. Hopefully, this won't cause issues in your other tables.

This is the result:

enter image description here

michal.h21
  • 50,697
  • Thanks Michael. This worked on the small examples I have. Will test it more on a large document with lots of tables also, but that takes 2 days to compile. – Nasser Nov 22 '23 at 09:27
  • @Nasser it compiles two days with MathJax math? That's insane. You could try to use -m draft for subsequent compilations for speed up. – michal.h21 Nov 22 '23 at 09:35
  • I am not sure what you mean by use -m draft for subsequent compilations and how. I am using your lua script you send me long time ago which decides if it needs to do more runs or not. Remember that? The large document is this I normally start the build on friday night and by early sunday it is done. I do not want to use "draft" then having to compile everything again? right? I always complained that tex4ht is very slow on large documents. May be because I am on Virtual box. – Nasser Nov 22 '23 at 09:52
  • Yes, this is using mathjax mode. That is all I use now. svg for math will probably take 7 days to compile this document. And I also think math in mathjax looks better than math using svg images. – Nasser Nov 22 '23 at 09:53
  • Ah, you use this script. I forgot about it, of course. Anyway, if you use VirtualBox, does it mean that you always start from scratch, without temporary files from previous compilations? This can lead to additional runs. – michal.h21 Nov 22 '23 at 10:35
  • I use your make4ht command once. Like this make4ht --shell-escape -ulm default -a debug -c nma_mathjax.cfg -e $TEXMFHOME/tex/latex/tex4ht_build_files/MAIN.mk4 $filename.tex "mathjax,htm,fn-in,notoc*,p-width,charset=utf-8,cut-fullname,nostyle" "-cunihtf -utf8" BUT before I issue this command, I remove all temporary files ofcourse as those are not needed, because this is done in Makefile, which detected that the latex file has changed. So why keep the old temp files around? – Nasser Nov 22 '23 at 10:40
  • So the work file is this: If the latex file has changed, then delete all temp files and call make4ht one time. It will take care of how many times it needs to re-run. Does this sound ok to you? I also run lualatex on same latex file on same folder. So it is more safe to remove any temp files to avoid clash. For example, the aux file is used by lualatex also. – Nasser Nov 22 '23 at 10:41
  • @Nasser it is safer to remove aux files, but it will lead to longer compilations. So you can try to not remove them. I never remove aux files and only occasionally run into problems. Also you can try to lower the value of local max_compilations = 6 to 3 or something like that. – michal.h21 Nov 22 '23 at 10:59
  • But Michal, if I do not delete the .aux file, it could have been generated by lualatex from some earlier compilation, since I use the same folder to compile both to PDF and HTML. Would that not cause errors and problems if tex4ht sees .aux there and tries to use it but it was generated by lualatex? – Nasser Nov 22 '23 at 11:05
  • @Nasser no, it should be OK after second TeX4ht compilation – michal.h21 Nov 22 '23 at 11:20