# Conditionals and arrayjobx

I am struggling with the use of conditionals, I have a basic example given below that will output the table included.

The code starts by defining \myletterA as the A character, and an array called \test as A,B,C. I have a function called \indenterer that I call inside my table loop below.

\documentclass[12pt]{article}
\usepackage[a6paper,landscape]{geometry}

\usepackage{arrayjobx}
\usepackage{ifthen}

\def\tand{&}

\begin{document}

\newcommand{\myletterA}{}
\myletterwriter{A}

\newarray\test
\newcommand{\indenterer}{%
\readarray{test}{A&B&C}%writes A,B,C to array test
\checktest(1)%reads the first value
\cachedata%returns the value last read by \checktest
\myletterA%returns the value stored i.e. A
\ifx\cachedata\myletterA%
a% \true case
\else%
b% false case
\fi%
}

\newcounter{it}
\begin{tabular}{ll}%
\hline%
\setcounter{it}{1}%
\whiledo{\theit<4}{%
{\indenterer} Y \tand z \\%
\stepcounter{it}%
}%
\end{tabular}

space
\checktest(1)
\cachedata
\myletterA

\end{document}


The output lines of the table should display \cachedata\myletterA_ Y Z where the _ is either an a or b. So my question is why is this code always executing the false case (note the letter b instead of a) even though both \cashdata and \myletterA expand to give the same result?

• Inside the \indenterer, just before \ifx add \show\cachedata\show\myletterA and you'll see \cachedata is just a "macro", while \myletterA is a "long macro". – Werner Jan 19 '16 at 20:35
• Thanks you two. I did not know about long vs not long, I'll have to look into it. – Bob Jan 19 '16 at 22:37

It's easy. ;-) With



the macro \myletterA is \long, whereas \cachedata is defined with \def that makes it non \long.

Just do



• Ah thanks egreg. I do have one more quick question, if I remove the {} surrounding \indenterer the code breaks with the error "Argument of \read@array has an extra }". Any idea why? – Bob Jan 19 '16 at 22:35
• @Bob The problem are the & in the argument to \readarray that are mistaken for alignment points. One should plunge in the code of arrayjobx for seeing precisely why. On the other hand, I consider the package not more than a toy: there are far better ways for coping with arrays. – egreg Jan 19 '16 at 22:40
• Why do you consider it such? What are the better ways to deal with arrays? – Bob Jan 19 '16 at 23:34
• @Bob Look at tex.stackexchange.com/search?q=arrayjobx+user%3A4427 and some of the linked answers – egreg Jan 19 '16 at 23:36