[texhax] nested macro and counter generation [better]

Uwe Lueck uwe.lueck at web.de
Sat May 10 00:19:52 CEST 2008

... my former list may not have helped you, sorry. But isn't it simply

      \newcounter{#1}\expandafter \newcommand \csname #1\endcsname}

? Then use \CREATE like \newcommand with the only difference that you omit 
the backslash starting the desired command name, or like \newenvironment 
omitting the final argument. 

But it is not entirely clear to me what you mean about the counters. 
Do you mean you may need more than one counter per one new command? Then perhaps

    \newcommand{\CREATE}[2][\empty\empty]{% effect: \def\@fortmp{\empty}%
      \expandafter \newcommand \csname #2\endcsname}

(tested). The \@for is a LaTeX internal. 
The mandatory argument would be the command name (without backslash), 
again use \CREATE similarly to \newcommand as above. If you want more 
than one counter, use the optional argument for a comma-separated list. 
E.g., \CREATE[a,b,c]{foo}[1]{\typeout{#1!!}} will obtain counter names 
fooa, foob, fooc. 

The last \CREATEid could be preceded with a, e.g., `-', to obtain counter names, 
e.g., foo-a, foo-b, foo-c: 

        \newcounter{#2\expandafter \ifx\CREATEid\empty \else -\CREATEid \fi}}%
      \expandafter \newcommand \csname #2\endcsname}

but \thefoo-a would break. Then you might define something like 

    \newcommand{\The}[1]{\csname the#1\endcsname}

to type \The{foo-a} instead of \thefoo-a. (Tested without-option and with [a,b,c]. ) 

And it is not clear wether you want that the counters are reset by others. 

HTH -- Uwe. 
Susan Dittmar <SDittmar at eureca.de> schrieb am 08.05.2008 13:42:03:

for a LaTeX document I would like to define a macro CREATE, which
- takes some arguments itself
- creates and accesses a counter with a name of the first argument
concatenated with some identifying letters (I need more than one such
- creates a macro with a name equal to the first argument, where other
arguments of the CREATE macro define specifics of this macro, and 
which itself takes some arguments

More information about the texhax mailing list