2

I would like to know how can I use a counter for defining other new counters.

Something like this:

\newcounter{foo}
\stepcounter{foo}

%% Perhaps more increments, this depends of the user.

%% And now, to create a new counter and command from foo.

\newcounter{\csname foofoo\thefoo\endcsname}
\def\csname mydyndef\thefoo\endcsname{definition...}

For example, with foo = 5, to create the counter foofoo5 and the command \mydyndef5.

And of course, to use it now:

This is my example \csname mydyndef\thefoo\endcsname,
with counter \csname thefoofoo\thefoo \endcsname.

But, of course, nothing of this works for me. And that is the question:

How can I achieve this?

This problem arises from searching a pure manual solution to this question: New list environment: automatic enumeration with "a posteriori" format, creating a counter (label@counterx) and saving the format in a command (\label@formatx) for each new depth (controlled by list@depth counter):

\newenvironment{labelist}{%%%

  \stepcounter{list@depth} %% Actual depth

  \ifnumcomp{\value{list@depth}}{=}{1} {
     \newcounter{label@counter1}
     \setcounter{label@coutner1}{0}

     \def\label@format1{\Alph{label@counter1}}

     \begin{list}{ \textbf{(\label@format1)}  }
                 { \usecounter{label@counter1 }
  }{
    %% Similar to the first case, but replacing 1 with the actual depth.
  }
}{
   %% Other code not-important here.
}
4
  • Would you please tell more about the intended usage?
    – egreg
    Nov 2, 2012 at 14:53
  • Ok, just now I edit the post to make it more complete.
    – ABu
    Nov 2, 2012 at 14:54
  • What in the proposed solution to the labelist question doesn't satisfy you? An approach such as this is definitely not recommendable.
    – egreg
    Nov 2, 2012 at 15:08
  • That it is a static solution. It works exactly as I need actually, but if I want to make it changes to adapt to other situations, I have to make this changes manually. Also, I can't pass my own parameters to the environment for customizing it. I need something any more general and dynamic.
    – ABu
    Nov 2, 2012 at 15:38

1 Answer 1

7
  • \newcounter does not take a macro token, but a simple name:

    \newcounter{foofoo\thefoo}
    
  • \def\csname redefines \csname, you need \expandafter:

    \expandafter\def\csname mydyndef\thefoo\endcsname{definition ...}
    
0

You must log in to answer this question.

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