# How to compare and see if an expanded command is equal to another

Okay, I'm processing a CSV file using datatool:

"TRANSID","DATE","QUANTITY"
"141f8b4a-e83e-4222-911a-5a977b4d0afca","11/9/2015","10"
"f15c1ef0-316b-4fdd-9c3a-8a111d60d27da","11/9/2015","50"
"f15c1ef0-316b-4fdd-9c3a-8a111d60d27da","11/9/2015","50"


The problem is I'd like for the last two lines to be combined onto a single page, so I need to check and see if they're equivalent --- not having any luck w/ that:

\documentclass{memoir}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{datatool}

\newcommand{\oldtransactionid}{false}

\newboolean{continuerecord}
\setboolean{continuerecord}{false}

\begin{document}%
Initial setup here\par
%
\DTLforeach*{data}{%
\orderNo=TRANSID, \date=DATE, \quantity=QUANTITY}%
{%
\DTLiffirstrow{Processing first record}{second or further record}%
%
\ifthenelse{\boolean{continuerecord}}%
{Continuing a record\par}%
{Not continuing a record, clear to new page\par}%false
%
\hspace*{-3bp}\fontsize{10bp}{22bp}\selectfont\hbox to 42bp{\quantity}\hbox to 72bp{\hspace*{30bp} \quantity}\hbox to 144bp{\hspace*{15bp}ITEMCODE}\hbox to 288bp{\hspace*{15bp}\orderNo\hfill}\par
%
\expandafter\ifstrequal\expandafter{\expandafter\oldtransactionid}{\expandafter\orderNo}%
{\setboolean{continuerecord}{true}T\par}%
{\setboolean{continuerecord}{false}F\par}%
OLD: \oldtransactionid \par
NEW: \orderNo\par
\edef\oldtransactionid{\orderNo}
}%
%
place last page here
\end{document}


I thinking adding \edef got me to the last hurdle --- I jut need a way to get the comparison to work properly --- and obviously the \expandafter commands aren't helping (also tried \immediate (which as egreg noted isn't right)).

also tried:

\expandafter\ifstrequal{\expandafter{\oldtransactionid}}{\expandafter{\orderNo}}%


As well as a crazy idea of writing out to scratch files and reading back in, which I'm sufficiently embarrassed by as to not be willing to show.

• \immediate does nothing unless followed by \write, \openout or \closeout. – egreg Nov 12 '15 at 15:45

You have to expand both macros passed to \ifstrequal, but the string of \expandafters you're using only affects the first (and not really, I'd say).

The standard technique, if the data is ASCII strings, is to use \edef:

\begin{filecontents*}{\jobname.csv}
"TRANSID","DATE","QUANTITY"
"141f8b4a-e83e-4222-911a-5a977b4d0afca","11/9/2015","10"
"f15c1ef0-316b-4fdd-9c3a-8a111d60d27da","11/9/2015","50"
"f15c1ef0-316b-4fdd-9c3a-8a111d60d27da","11/9/2015","50"
\end{filecontents*}

\documentclass{memoir}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{datatool}

\newcommand{\oldtransactionid}{false}

\newboolean{continuerecord}
\setboolean{continuerecord}{false}

\begin{document}

Initial setup here

\DTLforeach*{data}{\orderNo=TRANSID, \date=DATE, \quantity=QUANTITY}%
{%
\DTLiffirstrow{Processing first record}{second or further record}%
%
\ifthenelse{\boolean{continuerecord}}%
{Continuing a record\par}%
{Not continuing a record, clear to new page\par}%false
%
\hspace*{-3bp}\fontsize{10bp}{22bp}\selectfont\hbox to 42bp{\quantity}%
\hbox to 72bp{\hspace*{30bp} \quantity}%
\hbox to 144bp{\hspace*{15bp}ITEMCODE}%
\hbox to 288bp{\hspace*{15bp}\orderNo\hfill}\par
%
\begingroup\edef\x{\endgroup
\noexpand\ifstrequal{\oldtransactionid}{\orderNo}%
}\x
{\setboolean{continuerecord}{true}T\par}%
{\setboolean{continuerecord}{false}F\par}%
OLD: \oldtransactionid \par
NEW: \orderNo\par
\edef\oldtransactionid{\orderNo}
}

place last page here
\end{document}


• Thanks. I seem to've gotten it to work w/: \ifthenelse{\equal{\expandafter{\oldtransactionid}}{\expandafter{\orderNo}}}% – WillAdams Nov 12 '15 at 17:29
• @WillAdams I don't think the \expandafter are necessary; however, I wouldn't recommend \ifthenelse. – egreg Nov 12 '15 at 17:44