I am trying to define tabular rows using a macro which shall perform an conditional definition of the tabular row according to a given parameter. Please consider the following MWE:
\documentclass{article}
\newcommand{\test}[3]{
\ifnum\numexpr#1\relax=0
#2 & %#3
\else
#2 & #3
\fi
}
\begin{document}
\begin{tabular}{ll}
\test{0}{col1-1}{col1-2} \\
\test{1}{col2-1}{col2-2} \\
\end{tabular}
\end{document}
Removing the comment in the fifth line (#2 & %#3
⟶ #2 & #3
) leads to the error message Incomplete \ifnum; all text was ignored after line 14
. Even after hours of searching the web I am not able to solve this issue.
What am I doing wrong?
Edit
@David Carlisle, @egreg, and @Francis: Thank you all very much for your answers. I tried all of your examples, and they all solve my issue. Although I think that the solution of @egreg is the formally accurate way to go, I consider the solution of @David Carlisle to be more elegant for my use case just for the sake of simplicity and brevity, while considering the answer of @Francis as a workaround. So I decided to mark the answer of @David Carlisle as the accepted one, without wanting to neglect the other answers.
Thank you very much for your help!