# Use tabu with htlatex

I'm trying to export my Latex document to HTML, but run into problems using the tabu-environment.

As a test case I use the following source file

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{tabu}

\begin{document}

\begin{table}[htbp]
\begin{tabu} to \textwidth{X[1,m,c]|X[1,m,c]}
A & B \\
\hline
1 & 2 \\
\end{tabu}
\caption{Some test table-}
\label{tab:test}
\end{table}

\end{document}


This is then passed through make4ht as a wrapper (from what I get it is the same with using htlatex directly), which results in the following error message:

Package tabu Warning: \@arrayright is missing from the
(tabu)                definition of \endarray.
(tabu)                Comptability with delarray.sty is broken. on input line 6
.

! Argument of \g:Advance has an extra }.
<inserted text>
\par
l.6 \begin{document}

?


The command I used so far

make4ht -uf html5 -d html test.tex "fn-in"


With regard to several other packages I read something about redefining the environment to cope with such errors. Can anybody advise me how to do that for tabu?

Sidenotes:

• The output does not have to be perfectly aligned etc. I can run another script on the HTML output. But I need at least a valid table structure there.
• I'd like to leave tabu in the original sources as it is sometimes needed for the PDF output. I'd prefer using some (re-)definitions that only apply when using the HTML conversion.

The issue with tabu is that it redefines lot of LaTeX macros, which is the same thing as tex4ht does. And they clash with each other. It was quite hard to create patch file for tex4ht, tabu.4ht, that enabled to compile your sample document without errors:

% we must suppress \everyrow redefintion by tabu, so some macro patching is necessary
\def\tabu@AtBeginDocument{
\ifdefined\CT@arc@ \else \let\CT@arc@  \relax \fi
\ifdefined\CT@drsc@\else \let\CT@drsc@ \relax \fi
\let\tabu@arc@L \CT@arc@ \let\tabu@drsc@L \CT@drsc@
% \everyrow{}%
}

\let\orig:hline\hline
\def\tabu@firstline{\orig:hline}
\def\tabu@firsthline{\orig:hline}
\def\tabu@lastline  {\orig:hline}
\def\tabu@lasthline {\orig:hline}
% there is a clash between tabu and tex4ht on \hline handling
% we will just use \cr in place of \hline
\def\tabu@hline {\cr}% \tabu@hline

% this is basically a rewrite of the \tabu@select macro
% the original code just crashed everything
\def\tabu@select {%
\expandafter \tabuthepreamble
}% \tabu@select

\def\tabu@setup{\tabu@alloc@
\ifcase \tabu@nested
\let\tabu@afterendpar \par
\fi\fi\fi
\def\tabu@aligndefault{c}
\tabu@init
\tabu@indent
\else       % <nested tabu>
\def\tabu@aligndefault{t}
\let\tabudefaulttarget \linewidth
\fi
\let\tabu@thetarget \tabudefaulttarget \let\tabu@restored \@undefined
\edef\tabu@NC@list{\the\NC@list}\NC@list{\NC@do \tabu@rewritefirst}%
%\everycr{} % don't let tabu redefine \everycr
\let\@startpbox \tabu@startpbox % for nested tabu inside longtabu...
\let\@endpbox   \tabu@endpbox   % idem "    "    "    "    "    "
\let\@tabarray  \tabu@tabarray  % idem "    "    "    "    "    "
\tabu@setcleanup
% \tabu@setreset % this causes issues
}% \tabu@setup


Basically, it blocks execution of some tabu macros. It is not ideal, because it loses information about table rules and borders, but at least it produces a valid table. There is still one catch: it still breaks some low-level tex4ht definitions, which I was not able to fix in the tabu.4ht file. It needs to be fixed using the no-halign option. So the compilation of the file may look like this:

 make4ht -uf html5 -d html test.tex "fn-in,no-halign"


This is the result:

• Thanks! Is there some kind of repository of 4th files or tutorials how to create this? It seems my actual source file also has problems with other packages and I'd like to give it a try myself instead of bothering you for each single one. – Sirko Dec 24 '18 at 15:06
• @Sirko the .4ht files are included in TeX distribution. They are automatically generated from source TeX files and the process is quite difficult. The issue is that it is necessary to inspect both problematic package code and tex4ht sources when clash occur, which is quite difficult process. It is best to identify the problematic macros from the package, copy them to the .4ht file and fix it here. – michal.h21 Dec 24 '18 at 15:10
• @Sirko I am working on documentation here: github.com/michal-h21/tex4ht-doc there is a small section about the development, but it is far from done. – michal.h21 Dec 24 '18 at 15:11