# newcommand counter expansion problem

I am trying to write a macro to support producing a sequence of storyboards for an appendix in a two column IEEE paper.

Can the value of a counter be expanded immediately for a macro? Currently the value of \theboardnumber only expands to the final value. See the line with the comment % <- PROBLEM.

% #1 is the storyboard title
% #2 is the image filename
% #3 is the image reference name
% #4 is the image caption
% #5 is the story to go with the image
\newcommand\boardset[2]{\csdef{board:#1}{#2}}
\newcommand\boardget[1]{\csuse{board:#1}}
\newcounter{boardnumber}
\newcommand{\storyboard}[6]{ %
\stepcounter{boardnumber} %
\boardset{#3}{storyboard \theboardnumber} % <- PROBLEM
\begin{table*}[h!] %
\begin{tabular}{|l|r|} %
\hline %
\begin{minipage}[t]{0.70\linewidth} %
\vspace{0.1mm} %
\begin{center} %
\underline{\textbf{\boardget{#3}: #1}}\\ %
\end{center} %
#5 %
\end{minipage} & %
\begin{minipage}[t]{0.25\linewidth} %
\raisebox{-\height}
{\includegraphics[width=\textwidth]{#2}} %
\captionof{figure}{#4}\label{#3} %
\end{minipage} \\ \\ %
\hline %
\end{tabular} %
\end{table*} %
}


This code:

\storyboard{Appearance of 5 RGB white point sources}
{MagnifiedQuincunx_source}{fig:Quincunx_source}{Source image}
{Five point sources are presented to the subject.}

\storyboard{Appearance of 5 RGB white point sources centered on retina}
{MagnifiedQuincunx_target}{fig:Quincunx_target}{Target image}
{
If the center white point is on the optic axis,
this is how refraction and diffraction modify the image.
}

Fig.~\ref{fig:Quincunx_target} in \boardget{fig:Quincunx_target}
is the image formed on the retina when
Fig.~\ref{fig:Quincunx_source} in \boardget{fig:Quincunx_source}
is centered on the optic axis of a human retina.


Expands to:

Fig. 2 in storyboard 2 is the image formed on the retina when Fig. 1 in
storyboard 2 is centered on the optic axis of a
human retina.


The correct result should be:

Fig. 2 in storyboard 2 is the image formed on the retina when Fig. 1 in
storyboard 1 is centered on the optic axis of a
human retina.


Note that the number of the second reference to storyboard should be 1.

I have spent hours searching for a solution and tried many approaches including \immediate\write, \edef, \xdef, and many others.

I am probably doing something wrong so I am asking for help.

• It would be much easier to answer if you had provided a runnable example, your fragment uses lots of undefined commands. I would guess you are using etoolbox in which case you probably want to change \csdef to \csxdef to force expansion. – David Carlisle Jun 16 '19 at 17:56
• unrelated but the lines ending \stepcounter{boardnumber} % should be  \stepcounter{boardnumber}% as having a space before the % is essentially the same as having no %. – David Carlisle Jun 16 '19 at 17:57

Here is the corrected version using David Carlisle's comment. Copy the source to a .tex file and pdflatex interprets it as I had wanted. You will have to replace the "MagnifiedQuincunx_.*" files and names to something you have local to your machine.

Thank you, again.

\documentclass[10pt,twoside]{IEEEtran}

\usepackage{caption}
\usepackage{etoolbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% #1 is the storyboard title
% #2 is the image filename
% #3 is the image reference name
% #4 is the image caption
% #5 is the story to go with the image
\newcommand\boardset[2]{\csxdef{board:#1}{#2}}
\newcommand\boardget[1]{\csuse{board:#1}}
\newcounter{boardnumber}
\newcommand{\storyboard}[6]{%
\stepcounter{boardnumber}%
\boardset{#3}{storyboard \theboardnumber}%
\vspace{-7pt}%
\begin{table*}[h!]%
\begin{tabular}{|l|r|}%
\hline%
\begin{minipage}[t]{0.70\linewidth}%
\vspace{0.1mm}%
\begin{center}%
\underline{\textbf{\boardget{#3}: #1}}\\%
\end{center}%
#5%
\end{minipage} &%
\begin{minipage}[t]{0.25\linewidth}%
\raisebox{-\height}
{\includegraphics[width=\textwidth]{#2}}%
\captionof{figure}{#4}\label{#3}%
\end{minipage} \\ \\%
\hline%
\end{tabular}%
\end{table*}%
\vspace{-7pt}%
}

\begin{document}

\onecolumn

\section{Optics Storyboards}

\storyboard{Appearance of 5 RGB white point sources}
{img/MagnifiedQuincunx_source}{fig:Quincunx_source}{Source image}
{Five point sources are presented to the subject.}

\storyboard{Appearance of 5 RGB white point sources centered on retina}
{img/MagnifiedQuincunx_target}{fig:Quincunx_target}{Target image}
{
If the center white point is on the optic axis,
this is how refraction and diffraction modify the image.
}

Fig.~\ref{fig:Quincunx_target} in \boardget{fig:Quincunx_target}
is the image formed on the retina when
Fig.~\ref{fig:Quincunx_source} in \boardget{fig:Quincunx_source}
is centered on the optic axis of a human retina.

\twocolumn

\end{document}