[texhax] Macros that define other macros

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


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}[1]{%
        \expandafter\protected at edef\csname#1\endcsname{%}}






More information about the texhax mailing list