# Conditionals inside table

i have several documents that display tables. Certain rows are shared among documents, so they are in a separate file. These rows should contain if statements to print different things depending on the main file that calls them (each main file sets a command to a certain value). Unfortunately, the argument that is dictating this branching is itself argument of another branching in the command used to display rows.

The point is: this argument is often null {}, so i don't want anything displayed there, and when it's not null i want the argument (so far so good). Then, when i have the argument, sometimes, based on the file where i am, i want to print two different things.

Here's the MWE that does this:

\documentclass[]{article}
\usepackage[english]{babel}
\usepackage{ifthen}
\usepackage{tabularx}

\newcommand{\name}[0]{one}
\newcommand{\myrow}[3]{#1 \ifthenelse{\equal{#3}{}}{}{;#3} & #2 \\\hline}

\begin{document}
\begin{tabularx}{1\linewidth}{| X | X | }
\hline
\myrow{A}{B}{C}      %this one prints  | A;C | B |
\myrow{A}{B}{}       %this one prints  | A | B |
\input{non-functioning-row}
\end{tabularx}
\end{document}


Intuitively there'll be another file like this one with a single difference, it sets the \name to "two".

While file "non-funtioning-row" file contains

\myrow{A}{B}{\ifthenelse{\equal{\name}{one}}{one}{two}}


Some time ago i played with another if-then-else package that should be better than this one but failed to achieve what i want.

• the problem here is unrelated to tables, it is simply that nested \iftenelse \equal tests do not work the way you are expecting. \ifthenelse{...}{A}{B} does not expand to A (even if it results in the A branch being taken) so it will never test \equal to A in an outer \ifthenelse test. – David Carlisle Sep 9 '16 at 8:58

I suggest to use \ifx etc. and some test with \empty and definition of the test macros such that it is easier change the conditions, say \fooone and \footwo instead of literal one and two.

\documentclass[]{article}
\usepackage[english]{babel}
%\usepackage{ifthen}
\usepackage{tabularx}

\newcommand{\fooone}{one}
\newcommand{\footwo}{two}
\newcommand{\name}{one}
\makeatletter
\newcommand{\myrow}[3]{\def\foobar{#3}#1 \ifx\foobar\empty\else;#3\fi & #2\\ \hline}
\makeatother

\begin{document}
\begin{tabularx}{1\linewidth}{| X | X | }
\hline
\myrow{A}{B}{C}      %this one prints  | A;C | B |
\myrow{A}{B}{}       %this one prints  | A | B
\input{notworking}
\end{tabularx}
\end{document}


Whereas notworking.tex contains

\myrow{A}{B}{\ifx\name\fooone\relax\fooone\else \footwo\fi}


• there must be something wrong, as this thing prints the ";" in the second row as well, but that should only be printed when C is not {} – Squera Sep 9 '16 at 9:54
• @Squera: Replace \@empty by \empty, please – user31729 Sep 9 '16 at 9:59