1

I would like something like the following:

\documentclass{article}
\newcommand{\acell}{}
\newcommand{\bcell}
\newccomand{\zcell}[1]{#1}
\ifx\acell{A}
 \ifx\bcell{A}
  \zcell{yes}
 \else
  \zcell{no}
 \fi
\else
\fi
\begin{document}
\begin{tabular}{ccc}
\acell{A} & \bcell{A} & \zcell{} \\
\acell{A} & \bcell{B} & \zcell{} \\  
\end{document}

But this code does not work. It does not print "yes" and "no" where the 'zcell' macro is. Is it possible to achieve this?

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • Yes, it is, but under which rules? Besides the errors pointed out by David Carlisle, the conditions aren’t even inside a command but just in the preamble (and \newccomand is mis-typed). Do you want to test both cells whether they are A? – Qrrbrbirlbel Jun 08 '13 at 01:00

2 Answers2

5

You can do the following whereby I don't know what you want to achieve:

\documentclass[11pt]{article}
\makeatletter
\def\acell#1{\gdef\@acell{#1}}
\def\bcell#1{\gdef\@bcell{#1}}
\def\zcell{%
 \ifx\@acell\@bcell
     yes\acell{a}\bcell{b}%
 \else
   no
 \fi%
}
\makeatother
\begin{document}
\begin{tabular}{ccc}
\acell{A} & \bcell{A} & \zcell{} \\
\acell{A} & \bcell{B} & \zcell{} \\  
\end{tabular}
\end{document}

Some other hints:

David Carlisle
  • 757,742
Marco Daniel
  • 95,681
4

Your question isn't very clear (and your example is very incomplete) but I think you want

enter image description here

\documentclass{article}
\newcommand{\acell}[1]{\gdef\acontent{#1}#1}
\newcommand{\bcell}[1]{\gdef\bcontent{#1}#1}
\def\atest{A}
\newcommand{\zcell}{%
\ifx\acontent\atest
 \ifx\bcontent\atest
  yes%
 \else
  no%
 \fi
\else
  no%
\fi}
\begin{document}
\begin{tabular}{ccc}
\acell{A} & \bcell{A} & \zcell \\
\acell{A} & \bcell{B} & \zcell 
\end{tabular}
\end{document}

some notes on your example

\newcommand{\acell}{}

defines \acell to take no arguments and expand to nothing but you were using it as if it took an argument.

\newcommand{\bcell}

is a syntax error (you haven't provided a definition at all)

\newccomand{\zcell}[1]{#1}

just defines \zcell to echo its argument.

\ifx\acell{A}

is not in any definition and compares the token \acell to the token { then skips to the matching \fi as those tokens are not equal.

David Carlisle
  • 757,742