Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 8 '13 at 1:00
add comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
You add a picture :-) -- Should I add one too. –  Marco Daniel Jun 7 '13 at 23:05
add comment

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:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.