[texhax] Macros that define other macros

Uwe Lück uwe.lueck at web.de
Mon Dec 3 17:41:19 CET 2012


Sorry again for the previous posting due to that unintended 
key combination with Evolution ...

Am Montag, den 03.12.2012, 16:49 +0100 schrieb Uwe Lück:
> Am Montag, den 03.12.2012, 16:18 +0100 schrieb Uwe Lück:
> > \newcommand{\setobject}[4]{%
> >     \def\objectId{#1}%
> >     \@namedef  {propI|#1}{#2}%
> >     \@namedef {propII|#1}{#3}%
> >     \@namedef{propIII|#1}{#4}}
> > 
> > This way you could use \objectId to refer to the object's identifier 
> > in the second, third, and fourth argument of \setobject, such as 
> > 
> > \setobject{first}
> >           {First property of object `\objectId'}
> >           {Second property of object `\objectId'}
> >           {Third property of object `\objectId'}
> 
> Sorry, this was very wrong with respect to \objectId.
> 
> \newcommand{\setobject}[4]{%    
>     \@namedef  {propI|#1}{#2}%
>     \@namedef {propII|#1}{#3}%
>     \@namedef{propIII|#1}{#4}}
> 
> would be okay without the \objectId feature, which would mean 
> something like that properties do not know whose properties 
> they are.

... thinking of the original idea that the "submacro" actually 
reports whose submacro (property) it is. I find four possibilities 
for such an \objectId feature:

(i)

    \newcommand{\setobject}[4]{%
        \def\objectId{#1}%
        \@nameEdef  {propI|#1}{#2}%
        \@nameEdef {propII|#1}{#3}%
        \@nameEdef{propIII|#1}{#4}}
 
with 

    \newcommand{\@nameEdef}[1]{%
        \expandafter\protected at edef\csname#1\endcsname}

Then you can use \objectId and \protect in \setobject, 
and \protect may be essential in certain cases.

(ii)

    \newcommand{\setobject}[4]{% 
        \@nameOdef  {propI}{#1}{#2}%
        \@nameOdef {propII}{#1}{#3}%
        \@nameOdef{propIII}{#1}{#4}}
 
with 

    \newcommand{\@nameOdef}[3]{%
        \expandafter\protected at edef\csname#1\endcsname{%
            \@namedef{#1|#2}{\def\objectId{#2}#3}}}

This works without \protect, but is not robust.

(iii) and (iv) that I have in mind use a macro parameter 
instead of \objectId.

Cheers,

    Uwe.





More information about the texhax mailing list