I have a .csv-file, which I want to make into a table using the datatool-package. The .csv-file ist structured like
foo&bar&foobar
where several lines are grouped together and only the first in each group contains entries for foo and bar, the rest only for foobar. The entries may contain math.
I tried to check for the first line in a group with \ifdefempty from etoolbox-package and printing out \hline, if the entry for bar isn't empty, but this yields an error message.
MWP
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{datatool}
\DTLloaddb[keys={foo,bar,foobar}]{mydatabase}{testbase.csv}
\newcommand{\printcommand}[2][]{%
\begin{longtabu}to\textwidth{@{}llX@{}}
\firsthline
Foo&Bar&Foobar\\
\hline\endhead
\DTLforeach*{#2}{\foo=foo,\bar=bar,\foobar=foobar}{%
% \ifdefempty{\bar}{}{\hline}%
\foo&\bar&\foobar\\
}
\end{longtabu}
}
\begin{document}
foobar
\printcommand{mydatabase}
\end{document}
The testbase.csv looks like this
myfoo,mybar,myfoobar
17,barbar,bar 1
,,bar 234
,,barbary
23,ba ba ba,\(a^2+b^2=c^2\)
,,\emph{barfoo}
,,foofoofoo
If I compile like this, I get no errors, but if I uncomment the commented line, I get misplaced \noalin and misplaced \omit errors.
If I replace longtabu by tabu (and remove the then undefined \endhead), I get even more errors.
How can I make this work the way I want?

\linebreakin the code. Only\\and this ends previous lines of the table. – Toscho Jul 05 '17 at 15:07\crcras a result, that behaves like\crexcept if there was\crbefore, in which case, it does nothing. But this doesn't work here, as expected: If added before the\hlinein the commented line, it adds an empty line. So the\ifdefemptyseems to add something, so that\hlinebreaks, because it's not directly after newline and\crcris like\cr, because it's not directly after\cr. – Toscho Jul 05 '17 at 18:04\hlineto separate every\barcase - code. Note the use of\DTLiffirstrow. – Werner Jul 05 '17 at 18:14\DTLiffirstrowonly checks the first input line, but I would have to check for the first outputline of each page. – Toscho Jul 05 '17 at 18:42tabuorlongtabuunless you want buggy code which will break completely at some unspecified future date. – cfr Jul 06 '17 at 00:17tabu? – Toscho Jul 12 '17 at 17:53tabu's author. The author has promised backwards-incompatible changes and refuses to fix bugs in the meantime, even when provided with all the information required to do so. (That is, I'm not talking about refusing to spend hours trying to track down a bug in code you're about to replace anyway.) If you think that's 'just whining', fine. But don't look for any sympathy when you have to rewrite everytabuin your book or dissertation after inadvertently breaking it by updating your TeX installation. – cfr Jul 12 '17 at 23:06tabu', too? Gosh! How unfair! – cfr Jul 12 '17 at 23:10