I want to define some variables calculated in a loop to draw a path in tikzpicture. The variables are defined by some length (in pt) and the (section) title. For example, let's say we have:

  • 5pt, Section 1
  • 10pt, Section 2
  • 15pt, Section 3

This is done by a small calculation & reference on the section labels (to get the title):

\multiply\dimen1 by \frameNumber
\divide\dimen1 by \inserttotalframenumber

\expandafter\def\csname sWidth\the\value{sectionCounter} \endcsname{\progressbarwidthx}
\expandafter\def\csname sTitle\the\value{sectionCounter} \endcsname{\titlexyz}%


But if I call the variables after the loop by

\csname sWidth0 \endcsname
\csname sTitle0 \endcsname; %      
\csname sWidth1 \endcsname
\csname sTitle1 \endcsname; %        
\csname sWidth2 \endcsname
\csname sTitle2 \endcsname

all have assigned the same value from the last iteration: 15pt & Section 3

In the fist iteration sWidth0 & sTitle0 get the right value 5pt & Section 1, but already in the second iteration sWidth0 & sWidth1 and sTitle0 & sTitle1 get have the same values 10pt and Section 2, respectively.

Where is the problem?

Edit: I a generate this by hand the error does not occur:



\expandafter\newcommand\csname ary\the\value{sectionCounter} \endcsname{first}
\expandafter\newcommand\csname arz\the\value{sectionCounter} \endcsname{firstx}
\expandafter\newcommand\csname ary\the\value{sectionCounter} \endcsname{second}
\expandafter\newcommand\csname arz\the\value{sectionCounter} \endcsname{secondx}

\csname ary0 \endcsname
\csname ary1 \endcsname

\csname arz0 \endcsname
\csname arz1 \endcsname




  • 1
    Their value is \progressbarwidthx and \titlexyz respectively, not the expansion of these (because of the use of \def instead of \edef. The expansion takes place when you print them. Commented Jan 1, 2017 at 19:53

1 Answer 1



\expandafter\edef\csname sWidth\the\value{sectionCounter} \endcsname{\progressbarwidthx}
\expandafter\edef\csname sTitle\the\value{sectionCounter} \endcsname{\titlexyz}%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .