I've checked several questions (1, 2, 3, 4) about a problem with \if in a longtable (or tabular) environment but I haven't managed to get any smarter. I do have the following MWE:
\documentclass{article}
% some code normally residing in a .sty package
\usepackage{longtable}
\usepackage{array}
\makeatletter
\newif\if@test@testtrue
% [[A
% \newcommand{\thisline}[2]{\if@test\else{ \ #1 & #2 }\fi}
% \newcommand{\thatline}[2]{\if@test \ #1 & #2 \else\fi}
% ]] XOR [[B
\newcommand{\thisline}[2]{\if@test\else \ #1 & #2 \fi}
\newcommand{\thatline}[2]{\if@test{ \ #1 & #2 }\else\fi}
@testfalse
% ]]
% user-space code
\begin{document}
\begin{longtable}{ll}
\thisline{a}{b}
\thatline{c}{d}
\end{longtable}
\end{document}
The code works like this. However, if I set \@testfalse, I have to use block B instead of block A. Otherwise, I either get the "Missing } inserted" or the "Incomplete \iftrue; all text was ignored after line X" error. Obviously, I only want one of block A or B. So, what do I need to do in order to properly mask & (or \\, if that's the problem)?



\ifreally, in the false case you are generating a row{ a & b \\}which would generate the error you show even without the conditional. What is the intention of adding the brace group? – David Carlisle Sep 17 '21 at 10:37\@testfalseand without. It seemed to be the empty{}. If I remove all brace groups, it seems to work. Thanks. – mfg Sep 17 '21 at 10:46{}wouldn't error it's just adding an empty brace group in the same cell asa(although the space after it would affect the spacing) – David Carlisle Sep 17 '21 at 11:00\@testtrueand\@testfalsewithout using brace groups mutually in the unused/unexpandedifbranch? – mfg Sep 17 '21 at 11:34