Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.
}
share|improve this question
    
Would you please tell more about the intended usage? –  egreg Nov 2 '12 at 14:53
    
Ok, just now I edit the post to make it more complete. –  Peregring-lk Nov 2 '12 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 '12 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. –  Peregring-lk Nov 2 '12 at 15:38
add comment

1 Answer 1

up vote 5 down vote accepted
  • \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 ...}
    
share|improve this answer
    
Thank you, with this works perfectly. –  Peregring-lk Nov 2 '12 at 15:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.