# hide/show complete row of tabular

I need to toggle on/off full rows of a tabular via changing my preamble. My workflow only permits me to alter the first cell of each table in order to make it toggleable.

My idea was to use the accepted answer to this post \def taking rest of the line as argument and define a command \rowswitch that either swallows the whole row or displays it normally:

\documentclass{article}
\begin{document}
\newcommand*{\newlinecommand}[2]{%
\newcommand*{#1}{%
\begingroup%
\escapechar=\\%
\catcode\endlinechar=\active%
\csname\string#1\endcsname%
}%
\begingroup%
\escapechar=\\%
\lccode\~=\endlinechar%
\lowercase{%
\expandafter\endgroup
\expandafter\def\csname\string#1\endcsname##1~%
}{\endgroup#2\space}%
}

%toggles:
\newlinecommand{\rowswitch}{#1} %on
%\newlinecommand{\rowswitch}{} %off

\begin{tabular}{cc}
normal & row\\
\rowswitch toggle & row\\
normal & row
\end{tabular}
\end{document}


Unfortunately I keep receiving Forbidden control sequence found while scanning use of \\rowswitch is there anything I can do about this or is this doomed to fail?

I made a delimited macro that will read everything up to a \\, and a conditional \ifswitch that will or will not print the table row.

I provided two aliases \switchon and \switchoff to make it more intuitive :)

\documentclass{article}

\newif\ifswitch
\let\switchon\switchtrue
\let\switchoff\switchfalse

\def\rowswitch#1\\{%
\ifswitch%
#1\\
\fi%
}

\begin{document}

\switchon

\begin{tabular}{cc}
normal & row\\
\rowswitch toggle & row\\
normal & row
\end{tabular}

\bigskip

\switchoff

\begin{tabular}{cc}
normal & row\\
\rowswitch toggle & row\\
normal & row
\end{tabular}

\end{document}


I would just do

\documentclass{article}
\begin{document}

%toggles:
\def\rowswitch#1\\{#1\\} %On
%\def\rowswitch#1\\{} %Off

\begin{tabular}{cc}
normal & row\\
\rowswitch toggle & row\\
normal & row
\end{tabular}
\end{document}
`