# Creating and using commands/counters which name depends on other counter

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.
}

-
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

• \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 ...}
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5862387418746948, "perplexity": 2880.2192493557636}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-26/segments/1466783398516.82/warc/CC-MAIN-20160624154958-00194-ip-10-164-35-72.ec2.internal.warc.gz"}