# [texhax] Macros that define other macros

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

Dear Pablo, dear all,

please ignore the previous posting, my Ubuntu Mail program seems to
interpret a certain key combination as "send" while I don't want that.
(Continuing at \newcommand ...)

Am Montag, den 03.12.2012, 10:46 -0300 schrieb Pablo Mayckon:
> The doubling of the hashes was easy to understand. I also did a quick reading
> about "\csname" in the web and in principle understood how to use it. Later I
> will try to use these techniques and see whether I succeed. In any case, now I
> have a clear indication of what to study.
>
> Uwe: I really wanted the argument of \macromaker to be used in the names of
> its "submacros". The need for this was perhaps not clear from that
> artificially built example, but I do want to use it in my real context.

doubling hashes is actually wrong for what you have in mind,
when the outer parameter should be used in the inner definition(s).
Neal's idea is a better interpretation of your mail, I did not
properly try to make sense of "this is a submacro" and "this is
another submacro" (I may be trying again below).

The \csname thing actually is used with "LaTeX objects" such as
environments, counters, or references having an "identifier" like
your outer parameter where "properties" of such an object are coded
by "submacros" perhaps in your sense, each property with its own
"namespace" encoding it. Heiko Oberdiek has used this "view" and
terminology in his zref' package. His aliascnt' is a package that
"copies" objects under different identifiers, where the "class" of
"objects" just is that of "LaTeX counters".

For one class of objects with three properties, you could define
an object #1 by a macro \setobject as follows:

\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'}

Then with

\newcommand{\useobjectproperty}[2]{\csname #1|#2\endcsname}

you could call the single properties. There are smarter ways,
such as a definedness check producing an error as with
LaTeX's "environment" and "counter" classes.

[Not tested.]

Cheers,

Uwe.

P.S.: the key combination for "send" is "Ctrl-Enter", which has a
different meaning in my favourite text editor.

`