I want to fill a cells of a table with only a \item
command, and the \begin{itemize}
should be automatically inserted.
The following code works :
\newenvironment{matable}[0]{%
\begin{tabular}{l|p{5cm}}
theme & sujets \\ \hline\hline }
{\end{tabular}}
\newcommand{\messujets}[1]{ & \begin{itemize} #1 \end{itemize}\\ \hline}
\begin{matable}
\messujets{\item subject 1 \item subject 2}
\end{matable}
With the command \messujets
I start a new line in the table, and I fill the second cell with my \item
.
But if the argument of \messujets
happens to be empty, LaTeX complains about a missing \item
.
To avoid this, I want to have an \ifthenelse
test in the cell. My attempt is to replace:
\begin{itemize} #1 \end{itemize}
by
\ifthenelse{\equal{#1}{}}{\begin{itemize} #1 \end{itemize}}
So, it would be :
\newcommand{\messujets}[1]{ & \ifthenelse{\equal{#1}{}}{}{\begin{itemize} #1 \end{itemize}}\\ \hline}
But this produces an error use of \@item does not match its definition
which I do not understand…
Any idea?
Best Answer
The reason for the problem is that the
\equal
argument is a so called moving argument. That means it will break if it contains in its argument commands that are fragile and not protected by\protect
. And because of the optional argument\item
is fragile.In short using
\ifthenelse
here makes your life unnecessarily complicated as you would need to write something likeFor that reason a better approach is to use a lowlevel solution where you test for the argument being empty in a way that nothing is getting expanded and breaks. There are a number of ways to do this, e.g.,
This will work as long as the argument
#1
doesn't start with\foo
so by selecting some internal command for\foo
you can make sure that this is the case.