# Test for empty possibly itemized argument in tabu

For some reason, I can't test if #2 is empty in the following tabu use case. An

Incomplete \ifx; all text was ignored after line 14

is thrown executing the following code.

\documentclass{article}
\usepackage{tabu}
\usepackage[english]{babel}

\newcommand \test [2]{%
%Works
%#1  \ifx&#2& empty \else  {\begin{minipage}[t]{\linewidth}#2\end{minipage}} \fi

% Doesn't with Arg A
\begin{tabu}{XX} #1 & \ifx&#2& empty \else  {\begin{minipage}[t]{\linewidth}#2\end{minipage}} \fi \end{tabu}
}

\begin{document}%
\test{A}{\begin{itemize}\item Test\end{itemize}} % Arg A
%\test{A}{}
\end{document}


This seems to have something to do with how tabu examines cell contents. Adding a pair of braces helps.

I've also changed the emptiness test to something safer.

\newcommand\test[2]{%
\begin{tabu}{XX}
#1 &
{\if\relax\detokenize{#2}\relax
empty%
\else
\begin{minipage}[t]{\linewidth}#2\end{minipage}%
\fi}
\end{tabu}}


You have

 \ifx&


when TeX sees the & the cell ends and Tex switches in the code that ends the column definition. So here the \ifx will compare the first two tokens in the closing definition of the X column type in tabu, The following uses a safer test for empty.

Apart from that it's not clear why you would want to put a minipage in a X column as X columns are already parboxes?

\documentclass{article}
\usepackage{tabu}
\usepackage[english]{babel}

\makeatletter
\newcommand \test [2]{%
\begin{tabu}{XX}%
#1&%
\def\tmp{#2}%
\ifx\tmp\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{empty}%
{\begin{minipage}[t]{\linewidth}#2\end{minipage}}%
\end{tabu}}
\makeatother

\begin{document}%
\test{A}{\begin{itemize}\item Test\end{itemize}} % Arg A
\test{A}{}
\end{document}

• It breaks also with \ifx\relax#2\relax – egreg Apr 13 '13 at 15:10
• @egreg yes I noticed that:-) Changed to a safer test, I see you posted a different "safer test" in the meantime:-) – David Carlisle Apr 13 '13 at 15:26