Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I think there is a bug here.

Introduction

I use latex2html (L2H) to build some HTML Pages from LaTeX. The standard method to add L2H specific latex command is like this

\begin{htmlonly}
   % for L2H eyes only
\end{htmlonly}

This has been working fine for years. Hence the method to build the same LaTeX document with L2H and with pdfLaTeX is to do this

\documentclass{article}%
\usepackage{html}
\usepackage{ifpdf}
\begin{document}

\begin{htmlonly}
  %l2h only
\end{htmlonly}

%\begin{latexonly}    % WARNING, SPECIAL COMMENT DO NOT REMOVE
 \ifpdf
     %for pdflatex only
  \fi
%\end{latexonly}      % WARNING, SPECIAL COMMENT DO NOT REMOVE

\end{document}

and now I can do pdflatex foo.tex and do latex2html foo.tex and both are happy.

Problem when using tabu package

Now I wanted to use tabu package in pdfLaTeX only. So I used the above set up and wrote

\documentclass{article}%
\usepackage{html}
\usepackage{ifpdf}
\usepackage{longtable}
\usepackage{tabu}
\begin{document}

\begin{htmlonly}
 \begin{tabular}{|l|l|}
\end{htmlonly}

%\begin{latexonly}       % WARNING, SPECIAL COMMENT DO NOT REMOVE
 \ifpdf
   \begin{longtabu}{|l|l|}
  \fi
%\end{latexonly}

a&b\\
c&d\\

\begin{htmlonly}
  \end{tabular}
\end{htmlonly}

%\begin{latexonly}   % WARNING, SPECIAL COMMENT DO NOT REMOVE
\ifpdf
  \end{longtabu}
\fi
%\end{latexonly}

\end{document}

and now when I do pdflatex t9.tex I get this error:

(./t9.out) (./t9.out)
! Misplaced alignment tab character &.
<argument>  \fi \par a&
                       b\\ c&d\\ \par \par \begin {htmlonly} 
l.22   \end{tabular}

Which means tabu is looking at the tabular env. But this environment should never been seen by tabu.

Compare the above now, when I just use longtable. No tabu now. It works:

\documentclass{article}%
\usepackage{html}
\usepackage{ifpdf}
\usepackage{longtable,tabu}

\begin{document}

\begin{htmlonly}
 \begin{tabular}{|l|l|}
\end{htmlonly}

%\begin{latexonly}   % WARNING, SPECIAL COMMENT DO NOT REMOVE
 \ifpdf
   \begin{longtable}{|l|l|}
  \fi
%\end{latexonly}

a&b\\
c&d\\

\begin{htmlonly}
  \end{tabular}
\end{htmlonly}

%\begin{latexonly}  % WARNING, SPECIAL COMMENT DO NOT REMOVE
\ifpdf
   \end{longtable}
\fi
%\end{latexonly}

\end{document}

and now no error

>pdflatex t9.tex 
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
 restricted \write18 enabled.
.....
Output written on t9.pdf (1 page, 10799 bytes).
Transcript written on t9.log.
>

question is: why is tabu reading my htmlonly code?

I need to use longtabu since I read it can make longtable with same settings as tabularx which I needed.

I am using (TeX Live 2012/Debian) on Linux mint 14.

share|improve this question
2  
I don't think there's tex4ht compatibility code for tabu as there is for other packages. –  egreg Feb 3 '13 at 20:23
1  
You should nest the parts correctly: Move the htmlonly \end{tabular} behind the \end{longtabu}. Currently the htmlonly \end{tabular} is (quite unnecessarly) inside a cell and this is quite dangerous - even with less complex tabular commands then the one provided by tabu (you would get similar problems e.g. with amsmath tabulars). –  Ulrike Fischer Feb 4 '13 at 8:23
add comment

2 Answers

up vote 8 down vote accepted

It looks like you can hide the inner tabular code like this:

\relax\iffalse{\fi
\begin{htmlonly}
  \end{tabular}
\end{htmlonly}
\relax\iffalse}\fi
share|improve this answer
add comment

Well, since you ask "why", there are 2 reasons I believe:

  1. Package tabu pre-reads its contents and stores them somewhere before executing them. This makes the contents more like a macro argument than an envrionment contents. I'm not sure whether {htmlonly} environment can be used in macro arguments without any problems.

  2. As egreg points out, latex2html uses its own tweaks for various problematic environment (floats, tables, etc.) and there's obviously no such tweak done for tabu. You can propose a feature request to the maintainer of latex2html, since tabu is not much different from any other table-making environment, it should not be such a problem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.